Skip to content

Commit

Permalink
Create create CASTS if they do not already exist
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
  • Loading branch information
ritanwar committed Jan 13, 2025
1 parent 690cd99 commit d893122
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -44,17 +44,27 @@ RETURNS sys.BPCHAR
AS 'babelfishpg_common', 'fixeddecimal2bpchar'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE CAST (sys.FIXEDDECIMAL AS sys.VARCHAR)
WITH FUNCTION sys.fixeddecimal2varchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;
DO $$
DECLARE
exception_message text;
BEGIN
CREATE CAST (sys.FIXEDDECIMAL AS sys.VARCHAR)
WITH FUNCTION sys.fixeddecimal2varchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;

CREATE CAST (sys.FIXEDDECIMAL AS pg_catalog.VARCHAR)
WITH FUNCTION sys.fixeddecimal2varchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;
CREATE CAST (sys.FIXEDDECIMAL AS pg_catalog.VARCHAR)
WITH FUNCTION sys.fixeddecimal2varchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;

CREATE CAST (sys.FIXEDDECIMAL AS sys.BPCHAR)
WITH FUNCTION sys.fixeddecimal2bpchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;
CREATE CAST (sys.FIXEDDECIMAL AS sys.BPCHAR)
WITH FUNCTION sys.fixeddecimal2bpchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;

CREATE CAST (sys.FIXEDDECIMAL AS pg_catalog.BPCHAR)
WITH FUNCTION sys.fixeddecimal2bpchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;
CREATE CAST (sys.FIXEDDECIMAL AS pg_catalog.BPCHAR)
WITH FUNCTION sys.fixeddecimal2bpchar(sys.FIXEDDECIMAL, integer, BOOLEAN) AS IMPLICIT;
EXCEPTION WHEN duplicate_object THEN
GET STACKED DIAGNOSTICS
exception_message = MESSAGE_TEXT;
RAISE WARNING '%', exception_message;
END;
$$;

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);

0 comments on commit d893122

Please sign in to comment.