Skip to content

Commit

Permalink
move new casts to new common upgrade file
Browse files Browse the repository at this point in the history
Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 committed Nov 28, 2023
1 parent 4c0d558 commit fbddcde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,5 @@ BEGIN
END IF;
END $$;

-- typmod for sys.BBF_BINARY
CREATE OR REPLACE FUNCTION sys.bbf_binary (sys.BBF_BINARY, integer, boolean)
RETURNS sys.bbf_BINARY
AS 'babelfishpg_common', 'binary'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE CAST (sys.BBF_BINARY AS sys.BBF_BINARY)
WITH FUNCTION sys.bbf_binary (sys.BBF_BINARY, integer, BOOLEAN) AS ASSIGNMENT;

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@

SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false);

-- typmod for sys.BBF_BINARY
CREATE OR REPLACE FUNCTION sys.bbf_binary (sys.BBF_BINARY, integer, boolean)
RETURNS sys.bbf_BINARY
AS 'babelfishpg_common', 'binary'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

DO $$
DECLARE
sys_oid Oid;
bbf_binary_oid Oid;
BEGIN
sys_oid := (SELECT oid FROM pg_namespace WHERE pg_namespace.nspname ='sys');
bbf_binary_oid := (SELECT oid FROM pg_type WHERE pg_type.typname ='bbf_binary' AND pg_type.typnamespace = sys_oid);
IF (SELECT COUNT(*) FROM pg_cast WHERE pg_cast.castsource = bbf_binary_oid AND pg_cast.casttarget = bbf_binary_oid) = 0 THEN
CREATE CAST (sys.BBF_BINARY AS sys.BBF_BINARY)
WITH FUNCTION sys.bbf_binary (sys.BBF_BINARY, integer, BOOLEAN) AS ASSIGNMENT;
END IF;
END $$;

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/pltsql_coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ tsql_cast_raw_info_t tsql_cast_raw_infos[] =
{PG_CAST_ENTRY, "sys", "bbf_varbinary", "pg_catalog", "int4", NULL, 'i', 'f'},
{PG_CAST_ENTRY, "sys", "bbf_varbinary", "pg_catalog", "int2", NULL, 'i', 'f'},
{TSQL_CAST_ENTRY, "sys", "bbf_varbinary", "sys", "rowversion", "varbinaryrowversion", 'i', 'f'},
{TSQL_CAST_ENTRY, "sys", "bbf_varbinary", "sys", "bbf_binary", "binary", 'i', 'f'},
{TSQL_CAST_WITHOUT_FUNC_ENTRY, "sys", "bbf_varbinary", "sys", "bbf_binary", NULL, 'i', 'b'},
/* binary {only allow to cast to integral data type) */
{PG_CAST_ENTRY, "sys", "bbf_binary", "pg_catalog", "int8", NULL, 'i', 'f'},
{PG_CAST_ENTRY, "sys", "bbf_binary", "pg_catalog", "int4", NULL, 'i', 'f'},
Expand Down

0 comments on commit fbddcde

Please sign in to comment.