PostgreSQL: insert from another table

后端 未结 4 897
悲&欢浪女
悲&欢浪女 2021-01-30 00:39

I\'m trying to insert data to a table from another table and the tables have only one column in common. The problem is, that the TABLE1 has columns that won\'t accept null value

4条回答
  •  盖世英雄少女心
    2021-01-30 00:57

    For referential integtity :

    insert into  main_tbl (col1, ref1, ref2, createdby)
    values ('col1_val',
            (select ref1 from ref1_tbl where lookup_val = 'lookup1'),
            (select ref2 from ref2_tbl where lookup_val = 'lookup2'),
            'init-load'
           );
    

提交回复
热议问题