diff --git a/contrib/try_convert/data/tt_uuid.data b/contrib/try_convert/data/tt_uuid.data new file mode 100644 index 0000000000..6680d6384b --- /dev/null +++ b/contrib/try_convert/data/tt_uuid.data @@ -0,0 +1,6 @@ +a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 +A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11 +{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11} +a0eebc999c0b4ef8bb6d6bb9bd380a11 +a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11 +{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11} \ No newline at end of file diff --git a/contrib/try_convert/generate_test.py b/contrib/try_convert/generate_test.py index da271b9395..b8cceb1336 100644 --- a/contrib/try_convert/generate_test.py +++ b/contrib/try_convert/generate_test.py @@ -38,7 +38,7 @@ # # 'tsquery', # # 'tsvector', # # 'txid_snapshot', - # 'uuid', + 'uuid', 'citext', ] @@ -103,10 +103,11 @@ def remove_empty_lines(t): supported_extension_types_count = 0 for name in extension_types: - if name in extension_types: + if name in supported_types: supported_extension_types_count += 1 -print(f'Types found: {len(type_id_name)}, supported: {supported_types_count}, from ext: {len(extension_types)}, from ext sup {supported_extension_types_count}') +print(f'Types found: {len(type_id_name)}, supported: {supported_types_count}') +print(f'Extensions types found: {len(extension_types)}, supported: {supported_extension_types_count}') ### GET CONVERTS @@ -124,7 +125,13 @@ def remove_empty_lines(t): if type_id_name[int(source)] in supported_types and type_id_name[int(target)] in supported_types: supported_cast_count += 1 +supported_extension_casts_count = 0 +for s, t in extension_casts: + if s in supported_types and t in supported_types: + supported_extension_casts_count += 1 + print(f'Casts found: {len(casts)}, supported: {supported_cast_count}') +print(f'Extensions casts found: {len(extension_casts)}, supported: {supported_extension_casts_count}') ### HEADER & FOOTER @@ -133,6 +140,8 @@ def remove_empty_lines(t): f'-- SCRIPT-GENERATED TEST for TRY_CONVERT\n' \ f'-- Tests {supported_types_count} types of {len(type_id_name)} from pg_types.h\n' \ f'-- Tests {supported_cast_count} cast of {len(casts)} from pg_cast.h\n' \ + f'-- Tests {supported_extension_types_count} types of {len(extension_types)} from extensions\n' \ + f'-- Tests {supported_extension_casts_count} casts of {len(extension_casts)} from extensions\n' \ f'\n' \ f'create schema tryconvert;\n' \ f'set search_path = tryconvert;\n' \ diff --git a/contrib/try_convert/input/try_convert.source b/contrib/try_convert/input/try_convert.source index b29e8671b1..aab8a1e720 100644 --- a/contrib/try_convert/input/try_convert.source +++ b/contrib/try_convert/input/try_convert.source @@ -1,6 +1,8 @@ -- SCRIPT-GENERATED TEST for TRY_CONVERT --- Tests 21 types of 91 from pg_types.h +-- Tests 22 types of 91 from pg_types.h -- Tests 64 cast of 206 from pg_cast.h +-- Tests 1 types of 1 from extensions +-- Tests 3 casts of 8 from extensions create schema tryconvert; set search_path = tryconvert; @@ -223,6 +225,16 @@ $func$ -- do nothing: _out already carries default END $func$; +CREATE OR REPLACE FUNCTION try_convert_by_sql(_in uuid, INOUT _out ANYELEMENT) + LANGUAGE plpgsql AS +$func$ + BEGIN + EXECUTE format('SELECT %L::%s', $1, source_type) + INTO _out; + EXCEPTION WHEN others THEN + -- do nothing: _out already carries default + END +$func$; CREATE OR REPLACE FUNCTION try_convert_by_sql(_in citext, INOUT _out ANYELEMENT) LANGUAGE plpgsql AS $func$ @@ -300,6 +312,9 @@ INSERT INTO tt_text(id, v) SELECT row_number() OVER(), v::text from tt_temp; CREATE TABLE tt_money (id serial, v money) DISTRIBUTED BY (id); DELETE FROM tt_temp;COPY tt_temp from '@abs_srcdir@/data/tt_money.data'; INSERT INTO tt_money(id, v) SELECT row_number() OVER(), v::money from tt_temp; +CREATE TABLE tt_uuid (id serial, v uuid) DISTRIBUTED BY (id); +DELETE FROM tt_temp;COPY tt_temp from '@abs_srcdir@/data/tt_uuid.data'; +INSERT INTO tt_uuid(id, v) SELECT row_number() OVER(), v::uuid from tt_temp; CREATE TABLE tt_citext (id serial, v citext) DISTRIBUTED BY (id); DELETE FROM tt_temp;COPY tt_temp from '@abs_srcdir@/data/tt_citext.data'; INSERT INTO tt_citext(id, v) SELECT row_number() OVER(), v::citext from tt_temp; @@ -389,6 +404,10 @@ select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NU DELETE FROM tt_temp; COPY tt_temp from '@abs_srcdir@/data/tt_money.data'; select * from (select try_convert(v, NULL::money) as v1, try_convert_by_sql(v, NULL::money) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2); select * from (select try_convert(v, NULL::money) as v1, try_convert_by_sql(v, NULL::money) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_temp) as t(v)) as t(v1, v2) where not (v1 = v2); +select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_uuid) as t(v1, v2) where not (v1 = v2); +DELETE FROM tt_temp; COPY tt_temp from '@abs_srcdir@/data/tt_uuid.data'; +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2); +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_temp) as t(v)) as t(v1, v2) where not (v1 = v2); select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_citext) as t(v1, v2) where not (v1 = v2); DELETE FROM tt_temp; COPY tt_temp from '@abs_srcdir@/data/tt_citext.data'; select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, NULL::citext) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2); @@ -477,6 +496,10 @@ select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, DELETE FROM tt_temp_citext; COPY tt_temp_citext from '@abs_srcdir@/data/tt_money.data'; select * from (select try_convert(v, NULL::money) as v1, try_convert_by_sql(v, NULL::money) as v2 from tt_temp_citext) as t(v1, v2) where not (v1 = v2); select * from (select try_convert(v, NULL::money) as v1, try_convert_by_sql(v, NULL::money) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_temp_citext) as t(v)) as t(v1, v2) where not (v1 = v2); +select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, NULL::citext) as v2 from tt_uuid) as t(v1, v2) where not (v1 = v2); +DELETE FROM tt_temp_citext; COPY tt_temp_citext from '@abs_srcdir@/data/tt_uuid.data'; +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from tt_temp_citext) as t(v1, v2) where not (v1 = v2); +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_temp_citext) as t(v)) as t(v1, v2) where not (v1 = v2); select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, NULL::citext) as v2 from tt_citext) as t(v1, v2) where not (v1 = v2); DELETE FROM tt_temp_citext; COPY tt_temp_citext from '@abs_srcdir@/data/tt_citext.data'; select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, NULL::citext) as v2 from tt_temp_citext) as t(v1, v2) where not (v1 = v2); diff --git a/contrib/try_convert/output/try_convert.source b/contrib/try_convert/output/try_convert.source index 4b7526e786..b0ebd9e2ac 100644 --- a/contrib/try_convert/output/try_convert.source +++ b/contrib/try_convert/output/try_convert.source @@ -1,6 +1,8 @@ -- SCRIPT-GENERATED TEST for TRY_CONVERT --- Tests 21 types of 91 from pg_types.h +-- Tests 22 types of 91 from pg_types.h -- Tests 64 cast of 206 from pg_cast.h +-- Tests 1 types of 1 from extensions +-- Tests 3 casts of 8 from extensions create schema tryconvert; set search_path = tryconvert; -- start_ignore @@ -219,6 +221,16 @@ $func$ -- do nothing: _out already carries default END $func$; +CREATE OR REPLACE FUNCTION try_convert_by_sql(_in uuid, INOUT _out ANYELEMENT) + LANGUAGE plpgsql AS +$func$ + BEGIN + EXECUTE format('SELECT %L::%s', $1, source_type) + INTO _out; + EXCEPTION WHEN others THEN + -- do nothing: _out already carries default + END +$func$; CREATE OR REPLACE FUNCTION try_convert_by_sql(_in citext, INOUT _out ANYELEMENT) LANGUAGE plpgsql AS $func$ @@ -295,6 +307,9 @@ INSERT INTO tt_text(id, v) SELECT row_number() OVER(), v::text from tt_temp; CREATE TABLE tt_money (id serial, v money) DISTRIBUTED BY (id); DELETE FROM tt_temp;COPY tt_temp from '@abs_srcdir@/data/tt_money.data'; INSERT INTO tt_money(id, v) SELECT row_number() OVER(), v::money from tt_temp; +CREATE TABLE tt_uuid (id serial, v uuid) DISTRIBUTED BY (id); +DELETE FROM tt_temp;COPY tt_temp from '@abs_srcdir@/data/tt_uuid.data'; +INSERT INTO tt_uuid(id, v) SELECT row_number() OVER(), v::uuid from tt_temp; CREATE TABLE tt_citext (id serial, v citext) DISTRIBUTED BY (id); DELETE FROM tt_temp;COPY tt_temp from '@abs_srcdir@/data/tt_citext.data'; INSERT INTO tt_citext(id, v) SELECT row_number() OVER(), v::citext from tt_temp; @@ -635,6 +650,22 @@ select * from (select try_convert(v, NULL::money) as v1, try_convert_by_sql(v, N ----+---- (0 rows) +select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_uuid) as t(v1, v2) where not (v1 = v2); + v1 | v2 +----+---- +(0 rows) + +DELETE FROM tt_temp; COPY tt_temp from '@abs_srcdir@/data/tt_uuid.data'; +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2); + v1 | v2 +----+---- +(0 rows) + +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_temp) as t(v)) as t(v1, v2) where not (v1 = v2); + v1 | v2 +----+---- +(0 rows) + select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_citext) as t(v1, v2) where not (v1 = v2); v1 | v2 ----+---- @@ -987,6 +1018,22 @@ select * from (select try_convert(v, NULL::money) as v1, try_convert_by_sql(v, N ----+---- (0 rows) +select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, NULL::citext) as v2 from tt_uuid) as t(v1, v2) where not (v1 = v2); + v1 | v2 +----+---- +(0 rows) + +DELETE FROM tt_temp_citext; COPY tt_temp_citext from '@abs_srcdir@/data/tt_uuid.data'; +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from tt_temp_citext) as t(v1, v2) where not (v1 = v2); + v1 | v2 +----+---- +(0 rows) + +select * from (select try_convert(v, NULL::uuid) as v1, try_convert_by_sql(v, NULL::uuid) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_temp_citext) as t(v)) as t(v1, v2) where not (v1 = v2); + v1 | v2 +----+---- +(0 rows) + select * from (select try_convert(v, NULL::citext) as v1, try_convert_by_sql(v, NULL::citext) as v2 from tt_citext) as t(v1, v2) where not (v1 = v2); v1 | v2 ----+---- diff --git a/contrib/try_convert/try_convert--1.0.sql b/contrib/try_convert/try_convert--1.0.sql index 8511fa2e56..e7b6195fcd 100644 --- a/contrib/try_convert/try_convert--1.0.sql +++ b/contrib/try_convert/try_convert--1.0.sql @@ -48,6 +48,8 @@ select add_type_for_try_convert('bool'::regtype); select add_type_for_try_convert('money'::regtype); +select add_type_for_try_convert('uuid'::regtype); + -- IP/MAC select add_type_for_try_convert('cidr'::regtype); select add_type_for_try_convert('inet'::regtype);