db/schema/0012_newtype.sql

27 lines
1.0 KiB
MySQL
Raw Normal View History

2023-06-10 17:04:03 +00:00
create function create_newtype_text(qualified_name text)
returns void
language plpgsql
as $$
begin
execute concat('create type ', qualified_name, ' as (str text);');
execute concat( 'create function '
, qualified_name || '_to_string(val ' || qualified_name || ')'
, E' returns text language sql as \'select (val.str);\';'
);
execute concat( 'create function '
, qualified_name || '_of_string(val text)'
, ' returns ' || qualified_name || E' language sql as \'select row(val);\';'
);
execute concat( 'create cast '
, ' (' || qualified_name || ' as text)'
, ' with function ' || qualified_name || E'_to_string(' || qualified_name || ')'
, ' as assignment;'
);
execute concat( 'create cast '
, ' (text as ' || qualified_name || ')'
, ' with function ' || qualified_name || E'_of_string(text)'
, ' as assignment;'
);
2023-06-10 17:04:03 +00:00
end;
$$;