有没有什么方法可以转换 postgresql 9.3 数据类型,以便它只能影响一侧[重复]

2024-02-15

我正在使用 ppas9.3(兼容 Oracle),我想进行转换,使其仅影响一侧。 我想要的是,我想要一种在插入和比较期间可以接受整数和布尔值的数据类型,但没有取得任何成功,发生的主要问题是: 最初他们接受这些值:

In Postgresql:-
For Integer type datatype:-

insert into ask(aint) values(1,'1')         working
insert into ask(aint) values(true)      not working
select * from ask where aint=1,'1',true;    working


*For smallint type datatype:-

insert into ask(asmall) values(1,'1',true); working
select * from ask where asmall = 1,'1'      working
select * from ask where asmall = true   not working

For boolean type datatype:-

insert into ask(abool) values(1)        not working
insert into ask(abool) values(true)     working
select * from ask where abool=1,true    working

进行内部转换意味着更新“Integer”的 pg 表以在比较时接受“true”(布尔值)后,“Integer”列的行为完全恢复并开始与“smallint”相同,“smallint”也相同“布尔值”也一样。

所以我的问题是"Is there any internal casting is available in postgresql 9.3 so that it can affect only one side means either at the time of 'insertion' or at the time of 'comparison'"。因此,如果您有任何此类技术,请分享。谢谢。


演员阵容分为三种。源和目标类型的注册转换必须是“任务” (a) or “隐式”(i)工作于VALUES的表达INSERT陈述。看着系统目录pg_cast https://www.postgresql.org/docs/current/catalog-pg-cast.html,演员阵容来自boolean to integer仅定义“明确”(e):

SELECT castsource::regtype, casttarget::regtype, castfunc::regproc, castcontext
FROM   pg_cast
WHERE  castsource = 'bool'::regtype
AND    casttarget = 'int'::regtype;

Result:

castsource  casttarget  castfunc         castcontext
boolean     integer     pg_catalog.int4  e

Related:

  • 生成一系列日期 - 使用日期类型作为输入 https://stackoverflow.com/questions/21045909/generate-series-of-dates-using-date-type-as-input/21051215#21051215

你必须改变castcontext让它发挥作用 - 你can以超级用户身份执行。这种奇异的操作没有“ALTER CAST”声明,你必须UPDATE直接地。喜欢:

UPDATE pg_cast
SET    castcontext = 'a'
WHERE  castsource = 'bool'::regtype
AND    casttarget = 'int'::regtype;

However,每个演员的预定义演员上下文都有充分的理由。篡改系统目录不是一件你应该轻易做的事情。在这种特殊情况下,当 Postgres 必须选择匹配的演员时,它可能会导致决策不平衡。就像从一组重载函数中进行选择一样......

类似的程序integer -> boolean, int2 -> boolean, boolean -> int2, etc.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有什么方法可以转换 postgresql 9.3 数据类型,以便它只能影响一侧[重复] 的相关文章

随机推荐