Re: marking record origin in views

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Claudio Lapidus" <clapidus(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: marking record origin in views
Date: 2003-11-26 15:47:57
Message-ID: 15132.1069861677@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Claudio Lapidus" <clapidus(at)hotmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Riyad Kalla 2003-11-26 15:52:08 Re: Java Strings and quote marks
Previous Message Jason Tesser 2003-11-26 15:12:44 Re: pam authentication for postgres