Skip to content

Commit

Permalink
Add UUID type data
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Dec 2, 2024
1 parent 69c0ea4 commit effabb8
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
6 changes: 6 additions & 0 deletions contrib/try_convert/data/tt_uuid.data
Original file line number Diff line number Diff line change
@@ -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}
15 changes: 12 additions & 3 deletions contrib/try_convert/generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# # 'tsquery',
# # 'tsvector',
# # 'txid_snapshot',
# 'uuid',
'uuid',

'citext',
]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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' \
Expand Down
25 changes: 24 additions & 1 deletion contrib/try_convert/input/try_convert.source
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 48 additions & 1 deletion contrib/try_convert/output/try_convert.source
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
----+----
Expand Down Expand Up @@ -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
----+----
Expand Down
2 changes: 2 additions & 0 deletions contrib/try_convert/try_convert--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit effabb8

Please sign in to comment.