在我的Java应用程序中,我曾经有一个如下的sql查询:
INSERT INTO "KPI_MEASURE" (
id,
created_at,
kpi_project_id,
kpi_frequency_id,
kpi_metric_id,
branch,
value
)
SELECT
nextval('"KPI_MEASURE_ID_seq"'::regclass),
now(),
kpi_measure.kpi_project_id,
kpi_measure.kpi_frequency_id,
kpi_measure.kpi_metric_id ,
kpi_measure.branch ,
sum(kpi_measure.value)
FROM "KPI_MEASURE" kpi_measure
INNER JOIN "KPI_METRIC" kpi_metric ON kpi_measure.kpi_metric_id = kpi_metric.id
INNER JOIN "KPI_PROJECT" kpi_project ON kpi_measure.kpi_project_id = kpi_project.id
INNER JOIN "KPI_AGGREGATION_PROJECT" kpi_agg_project ON kpi_project.name = kpi_agg_project.child_project_name
WHERE kpi_metric.aggregated = false
GROUP BY kpi_measure.branch, kpi_measure.kpi_metric_id, kpi_measure.kpi_project_id, kpi_project.name, kpi_measure.kpi_frequency_id;
我用jdbcTemplate.update
执行了该sql,并且有效。但是最近我通过一个参数更改了now()
的值::today_date
,我在代码中加上了该参数:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(TODAY_DATE, today); // TODAY_DATE = today_date
jdbcTemplate.update(sql, parameters);
但是现在,它创建了一个错误:
org.springframework.jdbc.BadSqlGrammarException:PreparedStatementCallback;错误的SQL语法...嵌套的异常是org.postgresql.util.PSQLException:未安装hstore扩展。
我不知道为什么会出错,因为当我们要在jdbc查询中添加参数时,这是我被告知要做的事情。
列数据类型为timestamp without time zone
,而today
变量为String
类型。我想我应该使用Timestamp
,所以我更改了代码:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(TODAY_DATE, new Timestamp(System.currentTimeMillis())); // TODAY_DATE = today_date
jdbcTemplate.update(sql, parameters);
现在我只有这个错误
“ PSQLException:未安装hstore扩展。”
也许,我需要添加一个hstore,但是我似乎不明白为什么。
jdbcTemplate.update(sql, new Timestamp(System.currentTimeMillis()));