Unix Technical Forum

Feature request

This is a discussion on Feature request within the Pgsql General forums, part of the PostgreSQL category; --> One problem I've had in development recently is the inability to get the aliased name of a table from ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2008, 06:51 AM
Scott Miller
 
Posts: n/a
Default Feature request

One problem I've had in development recently is the inability to get the
aliased name of a table from a query. We're using a PHP framework for
querying, which internally uses pg_field_name to retrieve the select list
field name, which is great. There is alwo pg_table_name, to retrieve the
table the field originated from. The problem is that this returns the name
of the table, unaliased. If a query does a self join, you can't retrieve a
distinguishing table alias name for that field. For example:

SELECT a.mycolumn, b.mycolumn
FROM mytable a, mytable b
WHERE ...

If I controlled query generation at all times, I could simply alias
a.mycolumn and b.mycolumn differently in the select list. But if for
example this is SELECT * FROM, those columns are indistinguishable.

Cheers,
Scott

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-05-2008, 06:52 AM
Tom Lane
 
Posts: n/a
Default Re: Feature request

"Scott Miller" <smiller@duels.com> writes:
> One problem I've had in development recently is the inability to get the
> aliased name of a table from a query. We're using a PHP framework for
> querying, which internally uses pg_field_name to retrieve the select list
> field name, which is great. There is alwo pg_table_name, to retrieve the
> table the field originated from. The problem is that this returns the name
> of the table, unaliased. If a query does a self join, you can't retrieve a
> distinguishing table alias name for that field.


Supporting this would require a protocol change (to allow an additional
field in the result description message). So don't hold your breath :-(

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-05-2008, 06:52 AM
Scott Marlowe
 
Posts: n/a
Default Re: Feature request

On Fri, May 2, 2008 at 9:34 AM, Scott Miller <smiller@duels.com> wrote:
> One problem I've had in development recently is the inability to get the
> aliased name of a table from a query. We're using a PHP framework for
> querying, which internally uses pg_field_name to retrieve the select list
> field name, which is great. There is alwo pg_table_name, to retrieve the
> table the field originated from. The problem is that this returns the name
> of the table, unaliased. If a query does a self join, you can't retrieve a
> distinguishing table alias name for that field. For example:
>
> SELECT a.mycolumn, b.mycolumn
> FROM mytable a, mytable b
> WHERE ...
>
> If I controlled query generation at all times, I could simply alias
> a.mycolumn and b.mycolumn differently in the select list. But if for
> example this is SELECT * FROM, those columns are indistinguishable.


You have the same type of problem if you have this query:

select count(id), count(int2) from table.

They both are named count. The simple answer is to always alias your
select fields.

select count(id) as idcount, count(int2) as intcount from table.

or

SELECT a.mycolumn as a_mycol, b.mycolumn as b_mycol
FROM mytable a, mytable b
WHERE ...

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 11:17 AM
Scott Miller
 
Posts: n/a
Default Re: Feature request

On Sun, May 4, 2008 at 12:31 AM, Scott Marlowe <scott.marlowe@gmail.com>
wrote:

>
> You have the same type of problem if you have this query:
>
> select count(id), count(int2) from table.
>
> They both are named count. The simple answer is to always alias your
> select fields.
>
> select count(id) as idcount, count(int2) as intcount from table.
>


Of course. This is the a limitation stemming from the CakePHP web
development framework. In this case, it would assign those two fields to an
unnamed table/bucket, but for columns stemming from the from clause, it
splits them into buckets based on the table alias name. I can alias the
table names, but it means rewriting all the custom queries in the app, or
the resulting processing code which has been relying on the bucketizing.
Which is what I will do. Just another small speedbump moving my app away
from MySQL.

Scott

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com