can anyone help me with creating column for table A that are from table B ?
let's say i have table B:
column name:WORDS
row 1:ONE
row 2:TWO
row 3:THREE
and want to have table A:
column name: ONE | TWO | THREE
I need this to be created and not some VI开发者_运维问答EW
thanks
Something like...
create function create_my_table () as
$$
declare
v_t text[];
begin
select array_agg(distinct quote_ident(words) ||' text' ) into v_t from table_B;
EXECUTE 'CREATE TABLE tableA (' || array_to_string(v_t,',') ||' );';
end;
$$ language plpgsql;
select create_my_table;
You can use PostgreSQL's INHERITS syntax:
-- create tableB as a template
create table tableB(one varchar,two varchar,three varchar);
-- create tableA
create table tableA() INHERITS(tableB);
精彩评论