我正在尝试解决遗留数据库的问题。 quote_literal 函数不适用于 8.4 安装的 postgres 上的特定数据库。
这是我在新测试数据库上的结果:
select quote_literal(42);
quote_literal
---------------
'42'
(1 row)
现在在目标数据库上也是如此
select quote_literal(42);
ERROR: function quote_literal(integer) is not unique
LINE 1: select quote_literal(42);
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
AIUI,quote_literal(anyvalue) 函数应该可以正常处理整数值,这似乎得到了第一个测试的支持。
所以我认为 quote_literal 函数一定已在此数据库中被覆盖,但不,这似乎不是这种情况。我可以使用特定的 quote_literal(integer) 函数覆盖它,但我不明白为什么我必须这样做。
问题是是什么导致这个特定数据库中的这个函数失败而不影响新数据库?
最佳答案
另一种可能性:有人将文本的隐式转换添加到您的数据库中。 This was a common workaround for an intentional BC break in 8.3 .查看release notes for 8.3, E.57.2. Migration to Version 8.3
演示:
regress=# \df quote_literal
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+---------------+------------------+---------------------+--------
pg_catalog | quote_literal | text | anyelement | normal
pg_catalog | quote_literal | text | text | normal
(2 rows)
regress=# CREATE FUNCTION pg_catalog.text(integer) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int4out($1));';
CREATE FUNCTION
regress=# CREATE CAST (integer AS text) WITH FUNCTION pg_catalog.text(integer) AS IMPLICIT;
CREATE CAST
regress=# SELECT quote_literal(42);
ERROR: function quote_literal(integer) is not unique
LINE 1: SELECT quote_literal(42);
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
regress=#
这会修复它,但可能会破坏仍然依赖于强制转换的其他代码:
regress=# DROP CAST (integer AS text);
DROP CAST
regress=# SELECT quote_literal(42);
quote_literal
---------------
'42'
(1 row)
关于postgresql - 为什么这个 postgres 函数只在一个特定的数据库上失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13268312/