pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to alias table columns in result?
6+ messages / 4 participants
[nested] [flat]
* How to alias table columns in result?
@ 2005-08-10 22:45 nori <kodmasin@gmail.com>
2005-08-10 23:09 ` Re: How to alias table columns in result? Mischa Sandberg <mischa.sandberg@telus.net>
0 siblings, 1 reply; 6+ messages in thread
From: nori @ 2005-08-10 22:45 UTC (permalink / raw)
To: pgsql-sql
Hi,
If I have:
1.) table car with columns index and name
2.) table driver with columns index, name and car_index
and query:
SELECT d.*, c.* FROM driver as d LEFT OUTER JOIN car AS c ON
d.car_index=c.index;
How can I get results that have distinct names for columns (ex.
d.name, d.index, c.name, c.index,...)?
tnx
boris
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to alias table columns in result?
2005-08-10 22:45 How to alias table columns in result? nori <kodmasin@gmail.com>
@ 2005-08-10 23:09 ` Mischa Sandberg <mischa.sandberg@telus.net>
2005-08-11 09:48 ` Re: How to alias table columns in result? nori <kodmasin@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Mischa Sandberg @ 2005-08-10 23:09 UTC (permalink / raw)
To: pgsql-sql
Quoting nori <kodmasin@gmail.com>:
> Hi,
>
> If I have:
> 1.) table car with columns index and name
> 2.) table driver with columns index, name and car_index
>
> and query:
> SELECT d.*, c.* FROM driver as d LEFT OUTER JOIN car AS c ON
> d.car_index=c.index;
>
> How can I get results that have distinct names for columns (ex.
> d.name, d.index, c.name, c.index,...)?
Here's where you have to get explicit; d.* won't work.
If you want to have names with (.) in them, they have to be quoted, too.
Me, I'd use "d_name, d_index, c_name, ..."
SELECT d.name as "d.name",
d.index as "d.index",
c.name as "c.name",
...
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to alias table columns in result?
2005-08-10 22:45 How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-10 23:09 ` Re: How to alias table columns in result? Mischa Sandberg <mischa.sandberg@telus.net>
@ 2005-08-11 09:48 ` nori <kodmasin@gmail.com>
2005-08-11 09:56 ` Re: How to alias table columns in result? Nick Stone <nick@harelane.com>
0 siblings, 1 reply; 6+ messages in thread
From: nori @ 2005-08-11 09:48 UTC (permalink / raw)
To: Mischa Sandberg <mischa.sandberg@telus.net>; +Cc: pgsql-sql
Thanks
Sorry, my question was missing one important detail. My tables have
quite a lot columns (which unfortunately have same names in both
tables) so is it possible to do same as below but without specifying
alias for each column. Now my queries are long and they do not look
nice.
boris
On 8/11/05, Mischa Sandberg <mischa.sandberg@telus.net> wrote:
> SELECT d.name as "d.name",
> d.index as "d.index",
> c.name as "c.name",
> ...
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to alias table columns in result?
2005-08-10 22:45 How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-10 23:09 ` Re: How to alias table columns in result? Mischa Sandberg <mischa.sandberg@telus.net>
2005-08-11 09:48 ` Re: How to alias table columns in result? nori <kodmasin@gmail.com>
@ 2005-08-11 09:56 ` Nick Stone <nick@harelane.com>
2005-08-11 12:17 ` Re: How to alias table columns in result? nori <kodmasin@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Nick Stone @ 2005-08-11 09:56 UTC (permalink / raw)
To: 'nori' <kodmasin@gmail.com>; 'Mischa Sandberg' <mischa.sandberg@telus.net>; +Cc: pgsql-sql
Yes - just alias the columns you need to alias
Nick
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of nori
Sent: 11 August 2005 10:48
To: Mischa Sandberg
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] How to alias table columns in result?
Thanks
Sorry, my question was missing one important detail. My tables have quite a
lot columns (which unfortunately have same names in both
tables) so is it possible to do same as below but without specifying alias
for each column. Now my queries are long and they do not look nice.
boris
On 8/11/05, Mischa Sandberg <mischa.sandberg@telus.net> wrote:
> SELECT d.name as "d.name",
> d.index as "d.index",
> c.name as "c.name",
> ...
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to alias table columns in result?
2005-08-10 22:45 How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-10 23:09 ` Re: How to alias table columns in result? Mischa Sandberg <mischa.sandberg@telus.net>
2005-08-11 09:48 ` Re: How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-11 09:56 ` Re: How to alias table columns in result? Nick Stone <nick@harelane.com>
@ 2005-08-11 12:17 ` nori <kodmasin@gmail.com>
2005-08-11 12:22 ` Re: How to alias table columns in result? Jeff Boes <jeff@endpoint.com>
0 siblings, 1 reply; 6+ messages in thread
From: nori @ 2005-08-11 12:17 UTC (permalink / raw)
To: pgsql-sql; +Cc: Mischa Sandberg <mischa.sandberg@telus.net>
Ok I got it. There is no way to alias all columns of some table with
some "prefix" that will be visible in result except to alias each
column.
Tnx Nick, Micsha
P.S. sorry for my bad english
On 8/11/05, Nick Stone <nick@harelane.com> wrote:
> Yes - just alias the columns you need to alias
>
> Nick
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to alias table columns in result?
2005-08-10 22:45 How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-10 23:09 ` Re: How to alias table columns in result? Mischa Sandberg <mischa.sandberg@telus.net>
2005-08-11 09:48 ` Re: How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-11 09:56 ` Re: How to alias table columns in result? Nick Stone <nick@harelane.com>
2005-08-11 12:17 ` Re: How to alias table columns in result? nori <kodmasin@gmail.com>
@ 2005-08-11 12:22 ` Jeff Boes <jeff@endpoint.com>
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Boes @ 2005-08-11 12:22 UTC (permalink / raw)
To: pgsql-sql
nori wrote:
> Ok I got it. There is no way to alias all columns of some table with
> some "prefix" that will be visible in result except to alias each
> column.
Only other way would be to write a view for each table, then write all
your queries against the views.
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2005-08-11 12:22 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-10 22:45 How to alias table columns in result? nori <kodmasin@gmail.com>
2005-08-10 23:09 ` Mischa Sandberg <mischa.sandberg@telus.net>
2005-08-11 09:48 ` nori <kodmasin@gmail.com>
2005-08-11 09:56 ` Nick Stone <nick@harelane.com>
2005-08-11 12:17 ` nori <kodmasin@gmail.com>
2005-08-11 12:22 ` Jeff Boes <jeff@endpoint.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox