演员阵容分为三种。源和目标类型的注册转换必须是“任务” (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.