【发布时间】:2020-02-08 13:57:13
【问题描述】:
当我运行以下代码时
dataSource = new HikariDataSource(config);
try (Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement()) {
stmt.execute("SELECT drop_chunks(interval '24 hours', 'truck_message')");
ResultSet rs = stmt.getResultSet();
log.info("Executed drop_chunks() call. ResultSet: {}", rs);
} catch (SQLException ex) {
log.warn("Failed to execute drop_chunks() call", ex);
}
我收到以下错误:
WARN [Thread Group 1-3] c.g.TruckMessageSampler: Failed to execute drop_chunks() call
org.postgresql.util.PSQLException: ERROR: function drop_chunks(interval, unknown) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
我可以通过 psql postgres 客户端毫无问题地运行此查询,但不能通过使用 HikariCP 提供的 JDBC 连接的 Java 应用程序运行。我按照日志中的提示尝试了几种不同的想法:
我已经尝试了原始查询的另外两个变体
"SELECT drop_chunks(interval '24 hours', 'truck_message'::name)"
和
"SELECT drop_chunks(older_than => interval '24 hours', schema_name=> 'vitm'::name, table_name => 'truck_message'::name)"
这些都会导致相同的错误。该函数是 Timescaledb 扩展特定的,它是一个 postgres 扩展,定义如下:
someuser=# \df drop_chunks
List of functions
-[ RECORD 1 ]-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Schema | public
Name | drop_chunks
Result data type | SETOF regclass
Argument data types | older_than "any" DEFAULT NULL::unknown, table_name name DEFAULT NULL::name, schema_name name DEFAULT NULL::name, cascade boolean DEFAULT false, newer_than "any" DEFAULT NULL::unknown, "verbose" boolean DEFAULT false, cascade_to_materializations boolean DEFAULT NULL::boolean
Type | func
我在这里错过了什么?
【问题讨论】: