使用 JDBC 驱动程序时,Timescaledb drop_chunks() 调用失败并出现函数未找到错误
Timescaledb drop_chunks() call fails with function not found error when using JDBC driver
当我运行下面的代码
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 客户端 运行 这个查询没有问题,但不能通过我的 Java 应用程序使用 HikariCP 提供的 JDBC 连接。我按照日志中的提示尝试了几种不同的想法:
我尝试了原始查询的其他两个变体
"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
我在这里错过了什么?
好的,我需要的知识是函数是特定于模式的,所以在我的例子中,我必须指定一个模式。所以正确的查询是:
"SELECT public.drop_chunks(interval '24 hours', 'truck_message'::name)"
当我运行下面的代码
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 客户端 运行 这个查询没有问题,但不能通过我的 Java 应用程序使用 HikariCP 提供的 JDBC 连接。我按照日志中的提示尝试了几种不同的想法:
我尝试了原始查询的其他两个变体
"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
我在这里错过了什么?
好的,我需要的知识是函数是特定于模式的,所以在我的例子中,我必须指定一个模式。所以正确的查询是:
"SELECT public.drop_chunks(interval '24 hours', 'truck_message'::name)"