473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

marking record origin in views

Hello list

I have two tables with identical structure, one holds 'correct' data (from
an application standpoint) and the other has data 'in error'. Anyway, I need
sometimes to query both tables at the same time, so I constructed an
elementary view

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?

thanks
cl.
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
3 1421
Hmm, what about

create view v1 as
select *,1 as source from t1
union
select *,2 as source from t2;
Hello list

I have two tables with identical structure, one holds 'correct' data (froman application standpoint) and the other has data 'in error'. Anyway, I
need
sometimes to query both tables at the same time, so I constructed an
elementary view

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 nameof
the particular record source. How can this be done?


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #2
"Claudio Lapidus" <cl******@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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #3
"Peter Alberer" <h9******@obelix.wu-wien.ac.at> writes:
Hmm, what about

create view v1 as
select *,1 as source from t1
union
select *,2 as source from t2;


And you might want "UNION ALL". Otherwise the database has to go eliminate
duplicate records (and there won't be any duplicate records with the "source"
column there anyways).

--
greg
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Derek Cooper | last post by:
I hope you can help me. I posted this in the microsoft sql server newsgroup a few days ago and got no response so I thought I'd try here. If I can provide any clarification I'll be glad to do so....
3
by: Spartanicus | last post by:
How to get help from this group, and how to construct a minimised test case: http://www.spartanicus.utvinternet.ie/help_us_help_you.htm -- Spartanicus
2
by: allyn44 | last post by:
Hi--I have an unbound form that either edits an existing record or creates a new one and then refreshes a subform that views the record(s) chosen. What I would like to do from here is go to the...
4
by: steph | last post by:
Hi, A question regarding Access 2002: I've got a form which should be displayed in Form View and in Datasheet View. But I want to use a different record source for each view. That means, when...
1
by: mlwils2 | last post by:
I'm working with a report that uses three views. There are duplicate records because the 'priority' which comes from one view has changed and SELECT DISTINCT sees it as a separate record. The users...
3
by: Mike | last post by:
Stored Procedure: CREATE PROCEDURE . @BannerPage nvarchar(50), @MagazineID int AS BEGIN SET NOCOUNT ON;
6
by: ineedahelp | last post by:
Hi, I am trying to evaluate data in a table. First I need to evaluate NotionalValue for Symbols that match. If it passes my parameters, I need to apply my "flags" to the flag field. Instead of...
3
by: doc1355 | last post by:
I have a MS Access database with multiple forms for data entery. All the data are stored in one table, but I have multiple forms to organize the data entry. I also have a main form that shows the...
0
by: KEM827 | last post by:
In MS Access 2007, I want to switch between datasheet and form views, without filtering, and remain on the current record. Should I use a bookmark ? How ? or How might I place a button on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.