-
Notifications
You must be signed in to change notification settings - Fork 133
fix for char and nchar function correct handling #3855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
027e0dc
11ac3a8
8fa8985
295dddc
f04f307
00dbe04
2c9ae0b
b14d538
4b1b6b5
f28916d
b6793b7
3f8c48d
d190bc7
f290dae
ed7b626
57a2436
e6a5113
339c8a9
e1e35eb
25b99f8
58183b8
cb7533b
e249f6f
0cd0a3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,28 +97,34 @@ CREATE OPERATOR sys.+ ( | |
| FUNCTION = sys.babelfish_concat_wrapper | ||
| ); | ||
|
|
||
| create or replace function sys.CHAR(x in int)returns char | ||
| create or replace function sys.cht_(x in int) returns sys.varchar | ||
| AS | ||
| $body$ | ||
| BEGIN | ||
| /*************************************************************** | ||
| EXTENSION PACK function CHAR(x) | ||
| ***************************************************************/ | ||
| if x = 0 then | ||
| return ('\x00'::bytea)::sys.varbinary; | ||
| end if; | ||
| if x between 1 and 255 then | ||
| return chr(x); | ||
| else | ||
| return null; | ||
| end if; | ||
| END; | ||
| $body$ | ||
| language plpgsql STABLE; | ||
| LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should mark all the functions as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with stable we are not able to use the CHAR function in computed column, where as in tsql the char can be used in computed column.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have we verified that it is really
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the test case is passing in the JDBC parallel query mode, so we can say that it's parallel safe ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the pg_proc catalog too, we have verified that chr() function is parallel safe and since we are using chr() underlying sys.char(), so we can say it's parallel safe |
||
|
|
||
| CREATE OR REPLACE FUNCTION sys.nchar(IN x INTEGER) RETURNS sys.nvarchar | ||
| CREATE OR REPLACE FUNCTION sys.ncht_(x in int) RETURNS sys.nvarchar | ||
| AS | ||
| $body$ | ||
| BEGIN | ||
| --- 1114111 is 0x10FFFF - max value permitted as specified by documentation | ||
| if x between 1 and 1114111 then | ||
| if x = 0 then | ||
| return ('\x00'::bytea)::sys.varbinary; | ||
| end if; | ||
| --- 65535 is 0x0000FFFF - max value permitted as specified by documentation without SC collation | ||
| if x between 1 and 65535 then | ||
| return(select chr(x))::sys.nvarchar; | ||
| else | ||
| return null; | ||
|
|
@@ -127,16 +133,3 @@ END; | |
| $body$ | ||
| LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.nchar(IN x varbinary) RETURNS sys.nvarchar | ||
| AS | ||
| $body$ | ||
| BEGIN | ||
| --- 1114111 is 0x10FFFF - max value permitted as specified by documentation | ||
| if x::integer between 1 and 1114111 then | ||
| return(select chr(x::integer))::sys.nvarchar; | ||
| else | ||
| return null; | ||
| end if; | ||
| END; | ||
| $body$ | ||
| LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ int | |
| select coalesce(NULL, CHAR(9)) | ||
| go | ||
| ~~START~~ | ||
| text | ||
| varchar | ||
|
|
||
| ~~END~~ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ int | |
| select coalesce(NULL, CHAR(9)) | ||
| go | ||
| ~~START~~ | ||
| text | ||
| varchar | ||
|
|
||
| ~~END~~ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ int | |
| select coalesce(NULL, CHAR(9)) | ||
| go | ||
| ~~START~~ | ||
| text | ||
| varchar | ||
|
|
||
| ~~END~~ | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if input is
0? (Same for other functions as well)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this edge case need to be handled since pg function 'chr' expects the input b/w 1-255 where as the tsql expects input b/w 0-255. Thanks