Skip to content

Commit 06a29b0

Browse files
committed
RAWTOHEX function implementation
1 parent 97b5b0c commit 06a29b0

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

contrib/ivorysql_ora/expected/ora_raw_long.out

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,52 @@ SELECT * FROM LONG_TEXT ORDER BY II DESC;
175175
(3 rows)
176176

177177
DROP TABLE LONG_TEXT;
178+
179+
-- rawtohex
180+
SELECT sys.rawtohex('\xDEADBEEF'::bytea);
181+
rawtohex
182+
----------
183+
DEADBEEF
184+
(1 row)
185+
186+
SELECT sys.rawtohex('\xFF'::raw);
187+
rawtohex
188+
----------
189+
FF
190+
(1 row)
191+
192+
SELECT sys.rawtohex('hello'::text);
193+
rawtohex
194+
------------
195+
68656C6C6F
196+
(1 row)
197+
198+
SELECT sys.rawtohex('hello'::varchar2);
199+
rawtohex
200+
------------
201+
68656C6C6F
202+
(1 row)
203+
204+
SELECT sys.rawtohex(sys.hextoraw('DEADBEEF'));
205+
rawtohex
206+
----------
207+
DEADBEEF
208+
(1 row)
209+
210+
SELECT sys.rawtohex(NULL) IS NULL;
211+
?column?
212+
----------
213+
t
214+
(1 row)
215+
216+
SELECT sys.rawtohex('') IS NULL;
217+
?column?
218+
----------
219+
t
220+
(1 row)
221+
222+
SELECT sys.rawtohex('\x'::bytea) IS NULL;
223+
?column?
224+
----------
225+
t
226+
(1 row)

contrib/ivorysql_ora/sql/ora_raw_long.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ SELECT * FROM LONG_TEXT ORDER BY II DESC;
4444

4545
DROP TABLE LONG_TEXT;
4646

47+
-- rawtohex
48+
SELECT sys.rawtohex('\xDEADBEEF'::bytea);
49+
SELECT sys.rawtohex('\xFF'::raw);
50+
SELECT sys.rawtohex('hello'::text);
51+
SELECT sys.rawtohex('hello'::varchar2);
52+
SELECT sys.rawtohex(sys.hextoraw('DEADBEEF'));
53+
SELECT sys.rawtohex(NULL) IS NULL;
54+
SELECT sys.rawtohex('') IS NULL;
55+
SELECT sys.rawtohex('\x'::bytea) IS NULL;
56+

contrib/ivorysql_ora/src/builtin_functions/builtin_functions--1.0.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,23 @@ PARALLEL SAFE
952952
STRICT
953953
IMMUTABLE;
954954

955+
/* support rawtohex function for oracle compatibility */
956+
CREATE OR REPLACE FUNCTION sys.rawtohex(bytea)
957+
RETURNS varchar2
958+
AS $$ SELECT CASE WHEN pg_catalog.octet_length($1) > 0 THEN upper(pg_catalog.encode($1, 'hex'))::varchar2 END; $$
959+
LANGUAGE SQL
960+
PARALLEL SAFE
961+
STRICT
962+
IMMUTABLE;
963+
964+
CREATE OR REPLACE FUNCTION sys.rawtohex(text)
965+
RETURNS varchar2
966+
AS $$ SELECT CASE WHEN pg_catalog.octet_length($1) > 0 THEN upper(pg_catalog.encode($1::bytea, 'hex'))::varchar2 END; $$
967+
LANGUAGE SQL
968+
PARALLEL SAFE
969+
STRICT
970+
IMMUTABLE;
971+
955972

956973
/***************************************************************
957974
*

0 commit comments

Comments
 (0)