From 6279682c6de144821446f2721458f67705252e08 Mon Sep 17 00:00:00 2001 From: halphen Date: Wed, 11 Jan 2023 16:48:31 +0800 Subject: [PATCH 1/2] Update casts.sql --- sql_bits/casts.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql_bits/casts.sql b/sql_bits/casts.sql index 3287266..2a0e12f 100644 --- a/sql_bits/casts.sql +++ b/sql_bits/casts.sql @@ -1,3 +1,5 @@ +-- BOOLEAN TO BIT + -- TIME TO INTEGER CREATE OR REPLACE FUNCTION _time_to_integer(time with time zone) RETURNS integer AS $$ From b80dc7dcab12b27018d336440fc208d07eb6653c Mon Sep 17 00:00:00 2001 From: halphen Date: Mon, 6 Feb 2023 14:45:39 +0800 Subject: [PATCH 2/2] Update casts.sql Add BOOLEAN TO BIT, INT4 TO BIT, BIT TO INT4 --- sql_bits/casts.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sql_bits/casts.sql b/sql_bits/casts.sql index 2a0e12f..d9ceee0 100644 --- a/sql_bits/casts.sql +++ b/sql_bits/casts.sql @@ -1,4 +1,22 @@ -- BOOLEAN TO BIT +CREATE OR REPLACE FUNCTION _boolean_to_bit(BOOLEAN) +RETURNS bit AS $$ + SELECT + case $1 when true then 1::bit + else 0::bit end +$$ IMMUTABLE STRICT LANGUAGE SQL; + +CREATE CAST (BOOLEAN AS bit) + WITH FUNCTION _boolean_to_bit(BOOLEAN) + AS IMPLICIT; + +-- INT4 TO BIT(cast from type integer to type bit already exists) + -- select castsource::regtype,casttarget::regtype,castcontext,castfunc from pg_cast where castsource='integer'::regtype and casttarget='bit'::regtype; +update pg_cast set castcontext='i' where castsource ='integer'::regtype and casttarget='bit'::regtype; + +-- BIT TO INT4(cast from type bit to type integer already exists) + -- select castsource::regtype,casttarget::regtype,castcontext,castfunc from pg_cast where castsource='bit'::regtype and casttarget='integer'::regtype; +update pg_cast set castcontext='i' where castsource ='bit'::regtype and casttarget='integer'::regtype; -- TIME TO INTEGER CREATE OR REPLACE FUNCTION _time_to_integer(time with time zone)