PGSQL 复制表数据到新表

用 SELECT INTO

会根据查询条件生成一张新表包含查询的数据

select a.a1,a.a2,b.b1, '' as c1, null as c2 
 into new_table from  table_a a
left join table_b b on a.a1=b.b1;

用 INSERT INTO SELECT

先创建好表结构,然后插入查询的数据

insert into table_new(a1, a2, b1) select a.a1,a.a2,b.b1 
from  table_a a
left join table_b b on a.a1=b.b1;

你可能感兴趣的:(java)