34 lines
1.0 KiB
PL/PgSQL
34 lines
1.0 KiB
PL/PgSQL
alter type "public"."usr_username" rename attribute "username" to "str" cascade;
|
|
|
|
set check_function_bodies = off;
|
|
|
|
CREATE OR REPLACE FUNCTION public.create_newtype_text(qualified_name text)
|
|
RETURNS void
|
|
LANGUAGE plpgsql
|
|
AS $function$
|
|
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;
|
|
$function$
|
|
;
|
|
|
|
CREATE OR REPLACE FUNCTION public.usr_username_of_string(val text)
|
|
RETURNS usr_username
|
|
LANGUAGE sql
|
|
AS $function$select row(val);$function$
|
|
;
|
|
|
|
CREATE OR REPLACE FUNCTION public.usr_username_to_string(val usr_username)
|
|
RETURNS text
|
|
LANGUAGE sql
|
|
AS $function$select (val.str);$function$
|
|
;
|