Argumenty w procedurach - postresql

0

mam taką procedurę:

create procedure dbo.create_t_countries( )
language sql
as $$
create table dbo.countries (
    iso_code char(2) primary key,
    name varchar(64) not null,
    CONSTRAINT const_uniq1 unique (iso_code),
    CONSTRAINT const_uniq2 unique (name)
);
$$;

chcę by przyjmowała ona argument schemat, który będzie wskazywał schemat na jakim utworzyć tabelę countries. Jak użyć tego argumentu?

create procedure dbo.create_t_countries( schema varchar(16) )
language sql
as $$
create table ${schema}.countries (   -- ???
    iso_code char(2) primary key,
    name varchar(64) not null,
    CONSTRAINT const_uniq1 unique (iso_code),
    CONSTRAINT const_uniq2 unique (name)
);
$$;
2

Chyba tylko tak:

create function create_t_test(IN varchar default current_schema) returns void
language plpgsql
as $$
declare s text;
begin
s := '
create table if not exists ' || $1 ||'.test (
    iso_code char(2) primary key,
    name varchar(64) not null unique
)';
execute s;
end;
$$;

1 użytkowników online, w tym zalogowanych: 0, gości: 1