forked from babelfish-for-postgresql/babelfish_extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typmod for sys.binary datatype (babelfish-for-postgresql#2037)
sys.binary datatype is created as a domain over sys.bbf_binary. In babelfish we assume hex code as varbinary which must then be casted to binary. For casting we fetch rule from hashmap after coercing both source and target to base type. So binary --> bbf_binary && varbinary-->bbf_varbinary This cast is currently defined as binary coercible, that is NO modification needed. https://github.com/babelfish-for-postgresql/babelfish_extensions/blob/c57e8bc7820e1ef697dd9898b3aa433ba504a7ab/contrib/babelfishpg_tsql/src/pltsql_coerce.c#L114 We fix it by adding proper function for varbinary --> binary cast -> The default length for local variables defined for binary and varbinary should be 1 DECLARE @A binary should be equivalent to DECLARE @A binary(1) DECLARE @A varbinary should be equivalent to DECLARE @A varbinary(1) ->Problems during dump and restore done during upgrade. The new function created for the cast may not exists in the source version and the ugrade scripts are run only after pg dump and restore carried out during version upgrade. So ultimately during dump and restore no cast exists for varbinary to binary, which is a necessary requirement or upgrade will fail with error : _"pg_restore: error: could not execute query: ERROR: argument of DEFAULT must be type sys."binary", not type sys.varbinary"_. if we are dumping a procedure with sys.binary arg and a default value -> binary to varbinary we do not need to modify binary to varbinary cast since we have a type modifer defined for base type of sys.varbinary i.e. CAST(sys.bbf_varbiniary as sys.bbf_varbiniary). Task: BABEL-4544 Signed-off-by: Tanzeel Khan <[email protected]>
- Loading branch information
1 parent
d1f9dfd
commit 09721a5
Showing
43 changed files
with
615 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
contrib/babelfishpg_common/sql/upgrades/babelfishpg_common--2.6.0--3.0.0.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- complain if script is sourced in psql, rather than via ALTER EXTENSION | ||
\echo Use "ALTER EXTENSION ""babelfishpg_common"" UPDATE TO '3.0.0'" to load this file. \quit | ||
|
||
SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); | ||
|
||
/* This helper function would only be useful and strictly be used during 1.x->2.3 and 2.3->3.0 upgrade. */ | ||
CREATE OR REPLACE FUNCTION sys.babelfish_update_server_collation_name() RETURNS VOID | ||
LANGUAGE C | ||
AS 'babelfishpg_common', 'babelfish_update_server_collation_name'; | ||
|
||
SELECT sys.babelfish_update_server_collation_name(); | ||
|
||
DROP FUNCTION sys.babelfish_update_server_collation_name(); | ||
|
||
-- Reset search_path to not affect any subsequent scripts | ||
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/JDBC/expected/BABEL-3166-before-14_11-or-15_6-vu-prepare.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- function | ||
CREATE FUNCTION babel_3166_func(@a numeric, @b varchar, @c varchar(max), @d varchar(8), @e binary(6)) | ||
RETURNS varbinary(8) AS BEGIN RETURN @e END; | ||
go | ||
|
||
-- Look at the probin for typmod information | ||
SELECT proname, probin FROM pg_proc WHERE proname = 'babel_3166_func'; | ||
go | ||
~~START~~ | ||
varchar#!#text | ||
babel_3166_func#!#{"version_num": "1", "typmod_array": ["1179652", "-1", "-8000", "8", "6", "8"], "original_probin": ""} | ||
~~END~~ | ||
|
||
|
||
SELECT babel_3166_func(1.2, 'abc', 'abcd', 'abcdefgh', 0x12bcfe); | ||
go | ||
~~START~~ | ||
varbinary | ||
12BCFE | ||
~~END~~ | ||
|
||
|
||
-- procedure | ||
CREATE PROCEDURE babel_3166_proc @a numeric, @b varchar, @c varchar(max), @d varchar(8), @e binary(6) | ||
AS SELECT @e; | ||
go | ||
|
||
-- Look at the probin for typmod information | ||
SELECT proname, probin FROM pg_proc WHERE proname = 'babel_3166_proc'; | ||
go | ||
~~START~~ | ||
varchar#!#text | ||
babel_3166_proc#!#{"version_num": "1", "typmod_array": ["1179652", "-1", "-8000", "8", "6"], "original_probin": ""} | ||
~~END~~ | ||
|
||
|
||
EXEC babel_3166_proc 1.2, 'abc', 'abcd', 'abcdefgh', 0x12bcfe; | ||
go | ||
~~START~~ | ||
binary | ||
12BCFE000000 | ||
~~END~~ | ||
|
38 changes: 38 additions & 0 deletions
38
test/JDBC/expected/BABEL-3166-before-14_11-or-15_6-vu-verify.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- Look at function's probin for typmod information | ||
SELECT proname, probin FROM pg_proc WHERE proname = 'babel_3166_func'; | ||
go | ||
~~START~~ | ||
varchar#!#text | ||
babel_3166_func#!#{"version_num": "1", "typmod_array": ["1179652", "-1", "-8000", "8", "6", "8"], "original_probin": ""} | ||
~~END~~ | ||
|
||
|
||
SELECT babel_3166_func(1.2, 'abc', 'abcd', 'abcdefgh', 0x12bcfe); | ||
go | ||
~~START~~ | ||
varbinary | ||
12BCFE000000 | ||
~~END~~ | ||
|
||
|
||
|
||
DROP FUNCTION babel_3166_func; | ||
-- Look at procedures's probin for typmod information | ||
SELECT proname, probin FROM pg_proc WHERE proname = 'babel_3166_proc'; | ||
go | ||
~~START~~ | ||
varchar#!#text | ||
babel_3166_proc#!#{"version_num": "1", "typmod_array": ["1179652", "-1", "-8000", "8", "6"], "original_probin": ""} | ||
~~END~~ | ||
|
||
|
||
EXEC babel_3166_proc 1.2, 'abc', 'abcd', 'abcdefgh', 0x12bcfe; | ||
go | ||
~~START~~ | ||
binary | ||
12BCFE000000 | ||
~~END~~ | ||
|
||
|
||
DROP PROCEDURE babel_3166_proc; | ||
go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,7 +276,7 @@ SELECT CAST(CAST(0x61 AS BINARY(3)) AS VARBINARY(2)) | |
GO | ||
~~START~~ | ||
varbinary | ||
61 | ||
6100 | ||
~~END~~ | ||
|
||
|
||
|
Oops, something went wrong.