Thread: table.column in query results?

table.column in query results?

From
Andrew Klaassen
Date:
Hi,

Is it possible to get table.column in query results rather than just column?

I.e. I'd like:

SELECT * FROM foo, bar;
foo.id | foo.name | bar.id | bar.text
-------+----------+--------+---------
...

...rather than:

SELECT * FROM foo, bar;
id | name | id | text
---+------+----+-----
...

Thanks.

Andrew




      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now
http://ca.toolbar.yahoo.com.

Re: table.column in query results?

From
"Albe Laurenz"
Date:
Andrew Klaassen wrote:
> Is it possible to get table.column in query results rather
> than just column?
>
> I.e. I'd like:
>
> SELECT * FROM foo, bar;
> foo.id | foo.name | bar.id | bar.text
> -------+----------+--------+---------
> ...
>
> ...rather than:
>
> SELECT * FROM foo, bar;
> id | name | id | text
> ---+------+----+-----
> ...

You'd have to use aliases, like

SELECT id AS "foo.id" ...

Yours,
Laurenz Albe

Re: table.column in query results?

From
Jasen Betts
Date:
On 2009-07-22, Andrew Klaassen <clawsoon@yahoo.com> wrote:
> Hi,
>
> Is it possible to get table.column in query results rather than just column?

it is possible to get the OID of the table from libpq.
I don't think psql provides display of the table name as a
formatting option, and most wrapper around libpq seem to
ignore this feature.

if you can manipulate the query you can alias the column in
the query and hope that none of the tables or columns has a
dot in its name already!


Re: table.column in query results?

From
Andrew Klaassen
Date:
--- On Thu, 7/23/09, Albe Laurenz <laurenz.albe@wien.gv.at> wrote:

> Andrew Klaassen wrote:
> > Is it possible to get table.column in query results
> rather
> > than just column?
> >
> > I.e. I'd like:
> >
> > SELECT * FROM foo, bar;
> > foo.id | foo.name | bar.id | bar.text
> > -------+----------+--------+---------
> > ...
> >
> > ...rather than:
> >
> > SELECT * FROM foo, bar;
> > id | name | id | text
> > ---+------+----+-----
> > ...
>
> You'd have to use aliases, like
>
> SELECT id AS "foo.id" ...

Ah... so no way to do it with a wildcard in the query?

That's unfortunate.

Thanks.

Andrew




      __________________________________________________________________
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  Get it Now for Free! at
http://downloads.yahoo.com/ca/internetexplorer/