【技巧】PostgreSQL自动转换类型 int转bool 转int
【技巧】PostgreSQL自动转换类型 int转bool 转int
添加postgres数据转化规则(登录postgres 切换到自己的数据库,执行以下代码即可)
传入的bool隐式转为int
create or replace function bool_to_int(boolean) returns int2 as $$ select CAST($1::int as int2);
$$ language sql strict;
create cast (bool as int2) with function bool_to_int(boolean) as implicit;
另一个方案 修改系统默认值
默认为e
update pg_cast set castcontext='a' where castsource ='integer'::regtype and casttarget='boolean'::regtype;
castcontext | 含义 |
---|---|
i | implicit 隐式转换 |
a | assignment 赋值时允许 |
e | explicit 必须显式转换 |