Re: marking record origin in views - Mailing list pgsql-general

From Tom Lane
Subject Re: marking record origin in views
Date
Msg-id 15132.1069861677@sss.pgh.pa.us
Whole thread Raw
In response to marking record origin in views  ("Claudio Lapidus" <clapidus@hotmail.com>)
List pgsql-general
"Claudio Lapidus" <clapidus@hotmail.com> writes:
> create view v1 as select * from t1 union select * from t2;
> But I would like to have an extra field (in the view) with the table name of
> the particular record source. How can this be done?

What's wrong with

create view v1 as
  select *,'t1'::text as label from t1
 union
  select *,'t2'::text from t2;

Obviously, you can pick any field values and datatype you want.

Hint: use UNION ALL, not UNION.

            regards, tom lane

pgsql-general by date:

Previous
From: "Jason Tesser"
Date:
Subject: Re: pam authentication for postgres
Next
From: Greg Stark
Date:
Subject: Re: marking record origin in views