【问题标题】:postgresql function "idx" is found in some machine but not in other在某些机器上找到 postgresql 函数“idx”,但在其他机器上找不到
【发布时间】:2017-05-24 23:11:06
【问题描述】:

这是我使用PreparedStatement 执行的查询

SELECT planner.udf_desc.* FROM planner.udf_desc WHERE id IN(3,2) ORDER BY idx(array[3,2], id);

我在planner 架构中有一个名称为udf_desc 的表。
为了使它工作,我在我的数据库中安装了intarray 扩展

create extension "intarray"

我正在使用 linux 机器。我在其他三台机器(都是 linux)上进行了上述尝试。
但是现在当我在 Windows 机器上尝试同样的事情时。它不工作,我收到以下错误:

function idx(integer[], integer) does not exist

我在其他三台windows机器上试过了,还是不行。
我在服务器控制台上打印了堆栈跟踪

18:01:40,505 ERROR [com.ers.dao.UdfDao] (default task-13) SELECT planner.udf_desc.* FROM planner.udf_desc WHERE id IN(2) ORDER BY idx(array[2], id)
18:01:40,517 ERROR [stderr] (default task-13) java.sql.SQLException: ERROR: function idx(integer[], integer) does not exist
18:01:40,517 ERROR [stderr] (default task-13)   Hint: No function matches the given name and argument types. You might need to add explicit type casts.
18:01:40,520 ERROR [stderr] (default task-13)   Position: 73 Query: SELECT planner.udf_desc.* FROM planner.udf_desc WHERE id IN(2) ORDER BY idx(array[2], id) Parameters: []
18:01:40,522 ERROR [stderr] (default task-13)   at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392)
18:01:40,524 ERROR [stderr] (default task-13)   at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:351)
18:01:40,526 ERROR [stderr] (default task-13)   at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:289)

所有机器上的一切都是一样的,但idx 函数在一台机器上运行,而在另一台机器上不起作用。

【问题讨论】:

  • 你还需要在 Windows 安装上运行 create extension intarray
  • @a_horse_with_no_name 我做了,我做了我在 linux 系统中所做的一切。
  • 或者您在错误的数据库中创建了扩展。
  • 或者可能在错误的模式中(我注意到你用planner. 限定了你的表的名称......扩展和函数存在于特定的模式中,就像其他数据库对象一样,比如你的表;但是扩展有点特别:它们可以在每个数据库中创建一次——但仍然在一个模式中)。
  • @a_horse_with_no_name 我再次交叉检查了所有内容。问题是,无论我从一开始就重新安装所有东西,它都在某些机器上工作。但不能在具有相同安装方法的其他机器上工作。目前我观察到的是,它在任何 Windows 机器上都不起作用。如果您说在 99% 的情况下,问题在于连接、search_path 和权限。我可以向你保证连接是正确的。可能问题出在 search_path 或权限上。如果你能在这方面帮助我,请告诉我。

标签: java postgresql jdbc prepared-statement


【解决方案1】:

在 AWS RDS 上遇到了同样的问题。解决方案是删除扩展并重新创建它:

DROP EXTENSION intarray;
CREATE EXTENSION intarray;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-31
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    相关资源
    最近更新 更多