Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Feature req...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 15446 of 16301
Post > Topic >>

Re: Feature request

by scott.marlowe@[EMAIL PROTECTED] ("Scott Marlowe") May 3, 2008 at 11:31 PM

On Fri, May 2, 2008 at 9:34 AM, Scott Miller <smiller@[EMAIL PROTECTED]
> 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
> distingui****ng 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@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 4 Posts in Topic:
Feature request
smiller@[EMAIL PROTECTED]  2008-05-02 10:34:29 
Re: Feature request
tgl@[EMAIL PROTECTED] (T  2008-05-03 15:49:58 
Re: Feature request
scott.marlowe@[EMAIL PROT  2008-05-03 23:31:20 
Re: Feature request
smiller@[EMAIL PROTECTED]  2008-05-04 07:57:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 8:42:22 CDT 2008.