【问题标题】:Timescaledb drop_chunks() call fails with function not found error when using JDBC driver使用 JDBC 驱动程序时,Timescaledb drop_chunks() 调用失败并出现函数未找到错误
【发布时间】: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

我在这里错过了什么?

【问题讨论】:

    标签: postgresql timescaledb


    【解决方案1】:

    好的,我需要的知识是函数是特定于模式的,所以在我的例子中,我必须指定一个模式。所以正确的查询是:

    "SELECT public.drop_chunks(interval '24 hours', 'truck_message'::name)"
    

    【讨论】:

    • 您应该设置 search_path 使其包含 public。问题将得到解决。
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多