【问题标题】:PSQL Error: function does not existPSQL 错误:函数不存在
【发布时间】:2018-08-23 16:03:19
【问题描述】:

我在postgres中做了一个函数

CREATE OR REPLACE FUNCTION foobar(
    x TEXT,
    y TEXT,
    z REAL
) RETURNS BOOLEAN AS $func$
.
.
.
$func$ LANGUAGE plpgsql;

当我执行 \df 时,我得到以下信息:

+----------+--------+------------------+------------------------+---------+
|  Schema  |  Name  | Result data type |  Argument data types   |  Type   |
+----------+--------+------------------+------------------------+---------+
| mySchema | foobar | boolean          | x text, y text, z real | normal  |
+----------+--------+------------------+------------------------+---------+

但是当我尝试使用它时,我得到 [42883] 错误:函数 foobar(text, text, real) 不存在。提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。我正在打的电话是:

SELECT * FROM myTable WHERE foobar(column1::text, 'hello'::text, 7.2::real);

对我来说,函数似乎存在并且类型匹配,我正在努力找出问题所在。

【问题讨论】:

  • 您需要在其前面加上架构:where "mySchema".foobar(...)
  • 成功了,谢谢!
  • 请注意,用户需要架构上的USAGE 权限(例如public)才能执行功能。否则你会得到一个function does not exist 错误。

标签: postgresql


【解决方案1】:

正如a_horse_with_no_name 在他的评论中提到的,解决方案是在函数前面加上模式。

Wrong:   SELECT * FROM myTable WHERE foobar(column1::text, 'hello'::text, 7.2::real);
Correct: SELECT * FROM myTable WHERE mySchema.foobar(column1::text, 'hello'::text, 7.2::real);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
  • 2017-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多