我一直试图用Java编写查询以从2个时间戳之间的postgres时标数据库中选择数据,但是我不断收到Exception表示time_bucket函数不存在
由于我没有所有权,因此我无法将数据库中的timestamp列更改为Date,并且我尝试将查询复制粘贴到sql编辑器中,效果很好!
这是查询:
private final String SELECT_CANDLESTICK_BY_REQUEST = "SELECT " +
" time_bucket( interval '1 minute' , period_start_ts) AS periodts, " +
" count(*), " +
" first(metrics->>'askOpen',period_start_ts) as askOpen, " +
" max(metrics->>'askHigh') as askHigh, " +
" min(metrics->>'askLow') as askLow, " +
" last(metrics->>'askClose',period_start_ts) as askClose, " +
" first(metrics->>'bidOpen',period_start_ts) as bidOpen, " +
" max(metrics->>'bidHigh') as bidHigh, " +
" min(metrics->>'bidLow') as bidLow, " +
" last(metrics->>'bidClose',period_start_ts) as bidClose " +
" FROM candlestick_1_sec_fact " +
" where period_start_ts between ? and ? " +
" and symbol_cd = ? and liquidity_source_nm = ? " +
" GROUP BY periodts " +
" ORDER BY periodts" ;
这是我设置参数的方式:
PreparedStatement select = connection.prepareStatement(SELECT_CANDLESTICK_BY_REQUEST);
select.setTimestamp(1, new Timestamp(startTime));
select.setTimestamp(2, new Timestamp(endTime));
select.setString(3, symbol);
select.setString(4, source);
这是我得到的例外:
org.postgresql.util.PSQLException: ERROR: function time_bucket(interval, timestamp without time zone) does not exist . Hint: No function matches the given name and argument types. You might need to add explicit type casts.
即使我在查询中删除了interval关键字,它仍然无法识别time_bucket函数。
提前感谢您的时间和知识!