简体   繁体   English

将强制转换范围仅限制为PostgreSQL中的模式

[英]Limit cast scope only to schema in PostgreSQL

Funambol in its administration documentation has that for running on newer PostgreSQL instances which are more strict with types and casting you have to add those casts: Funambol在其管理文档中具有要在较新的PostgreSQL实例上运行的要求,这些实例对类型和类型转换更加严格,则必须添加这些类型转换:

CREATE FUNCTION pg_catalog.text(bigint) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int8out($1));';
CREATE CAST (bigint AS text) WITH FUNCTION pg_catalog.text(bigint) AS IMPLICIT;
CREATE FUNCTION pg_catalog.text(integer) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int4out($1));';
CREATE CAST (integer AS text) WITH FUNCTION pg_catalog.text(integer) AS IMPLICIT;

The problem is that in the same database (in PostgreSQL terminology) I have also other schemas which applications broke because of those casts (with "operator is not unique: unknown || integer" and hint "Could not choose a best candidate operator. You might need to add explicit type casts.") while they worked before. 问题在于,在同一个数据库中(使用PostgreSQL术语),我还有其他模式,这些应用程序由于这些强制转换而中断了(使用“运算符不是唯一的:unknown || integer”,并提示“无法选择最佳候选运算符。可能需要先添加显式类型转换。”)

So one solution is of course to define additional database and have only Funambol in there. 因此,一种解决方案当然是定义其他数据库,并且其中仅包含Funambol。 But I am wondering if is there a way to define those casts so that they take effect only in Funambol's schema and not in whole database. 但是我想知道是否有一种方法来定义这些强制类型转换,以便它们仅在Funambol的模式中而不在整个数据库中生效。

No, it's not possible in the way you imagine it. 不,按照您的想象是不可能的。 Casts are identified by source and target type, and so if both types are one of the built-in types, all users of the database will see the same casts between them. 强制转换由源和目标类型标识,因此,如果这两种类型都是内置类型之一,则数据库的所有用户将在它们之间看到相同的强制转换。 The only workaround along that line would be to create clones of the built-in data types, but don't go there. 唯一的解决方法是创建内置数据类型的克隆,但不要去那里。 ;-) ;-)

So you either need to seek a fix with Funambol, or separate your applications into different databases, and perhaps link them back together with something like dblink. 因此,您需要使用Funambol寻求修复,或者将您的应用程序分离到不同的数据库中,并可能通过dblink之类将它们链接回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM