0
votes

I need to insert data from one table into three 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 and table_3 have the same obj_id (type serial).

Any ideas on how to do that?

1
use triggers in postgresql, AFTER INSERTMani Deep
Do you really have columns that are named row_1?a_horse_with_no_name
No it is an example..var29

1 Answers

0
votes

You should repeat the code bellow for each of the tables:

INSERT INTO table_1 (id, row_1)
SELECT id, row_1
FROM source_table

If you have serial ("auto increment") column, look at this answer: SET IDENTITY_INSERT postgresql

In SQL Server, you need to set identity_insert on first and turn it off at the end.