SELECT multiple tables with same fields - Mailing list pgsql-sql

From Dipl.-Ing. Thomas Schallar
Subject SELECT multiple tables with same fields
Date
Msg-id 37C95508.B50F49BD@AVALON.at
Whole thread Raw
Responses Re: [SQL] SELECT multiple tables with same fields  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [SQL] SELECT multiple tables with same fields  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-sql
Hello!

Imagine two tables

CREATE TABLE one ( name varchar(10), content varchar(10) );
CREATE TABLE two ( name varchar(10), something_different varchar(10) );

with some rows in each of them and and a query

SELECT *
INTO new_table
FROM one, two
WHERE one.name=two.name;

If there are matching fields, then the query would return some joined
rows. But it can't, because the column "name" comes twice in the tables!
Of course

SELECT one.*, two.name AS two_name, two.something_different
INTO new_table
FROM one, two
WHERE one.name=two.name;

does the work, because I rename the duplicate columns.

Before I started programming with Postgres I've done my stuff with
Microsoft Visual Basic and Access. Access has the lovely feature, that
doubly selected column names are automatically renamed to
<tablename>.<columname> (or <tablename>_<columname>? I can't remember at
the moment; sorry!) so everything works fine.

Is there some similar feature in Postgres? I'm asking, because I have
queries over up to seven tables joined and the fields in those tables
are growing larger and larger. But if I add fields, than I have to add
them to each of the SELECT statements also, that they won't be missed
off. That's boaring und faulty.

Any help welcome!

regards,
Thomas
(Vienna, Austria, Europe)




pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] entries in pg_shadow
Next
From: "Dipl.-Ing. Thomas Schallar"
Date:
Subject: LEFT or RIGHT JOINs?