feat: create_newtype_text
This commit is contained in:
parent
047a51b45d
commit
49bed63d07
16
schema/000_newtype.sql
Normal file
16
schema/000_newtype.sql
Normal file
@ -0,0 +1,16 @@
|
||||
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);\';'
|
||||
);
|
||||
end;
|
||||
$$;
|
@ -1,4 +1,4 @@
|
||||
create type public.usr_username as (username text);
|
||||
select create_newtype_text('public.usr_username');
|
||||
|
||||
create table public.usr_audit
|
||||
( usr int not null
|
||||
|
Loading…
Reference in New Issue
Block a user