Postgres 将查询结果同时插入数据表

时间:2022-01-10 14:32:13
INSERT INTO table [ ( column [, ...] ) ]
 { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
 [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

 

 INSERT INTO SELECT 可以将 select 的结果集同时插入到另一个指定的表中,大大提高了效率,如下:

INSERT INTO 
    widgets
    (
        map_id,
        widget_name
    )
SELECT 
   mt.map_id,
   'Bupo'
FROM
    map_tags mt
WHERE
    mt.map_license = '12345'