postgresql - Insert coulmns of 1 table into multiple tables as row all having same ID -


i need insert data 1 table 3 different tables (see example below):

before

source_table:     id row_1 row_2 row_3 

after

table_1: obj_id row_1  table_2: obj_id row_2  table_3: obj_id row_3 

table_1, table_2 , table_3 have same obj_id (type serial).

any ideas on how that?

you should repeat code bellow each of tables:

insert table_1 (id, row_1) select id, row_1 source_table 

if have serial ("auto increment") column, @ answer: set identity_insert postgresql

in sql server, need set identity_insert on first , turn off @ end.


Comments