update pg_cast set castcontext='a' where castsource ='boolean'::regtype and casttarget='integer'::regtype;
update pg_cast set castcontext='a' where castsource ='integer'::regtype and casttarget='boolean'::regtype;
CREATE OR REPLACE FUNCTION int_to_boolean(i smallint) RETURNS boolean AS $$
BEGIN
RETURN (i::smallint)::int::bool;
END;
$$ LANGUAGE plpgsql;
CREATE CAST (smallint AS boolean) WITH FUNCTION int_to_boolean(smallint) AS ASSIGNMENT;
CREATE OR REPLACE FUNCTION boolean_to_int(i boolean) RETURNS smallint AS $$
BEGIN
RETURN (i::boolean)::bool::int;
END;
$$ LANGUAGE plpgsql;
CREATE CAST (boolean AS smallint) WITH FUNCTION boolean_to_int(boolean) AS ASSIGNMENT;
pg数据库整型与布尔互换
最新推荐文章于 2024-07-15 17:28:09 发布