postgresql中union联合查询,怎么给查询到的每条记录加一个字段,表示这条记录来自哪个表?
就像你说的,查的时候加个字段就是了呗
select 'table_a' table_name , a.col1,a.col2 from table_a a
union all
select 'table_b' table_name, a.col1,a.col2 from table_b b