Re: About primary keys.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tim Andersen <timander37(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: About primary keys.
Date: 2003-08-15 15:57:40
Message-ID: 18736.1060963060@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tim Andersen <timander37(at)yahoo(dot)com> writes:
> The query I have so far only gets columns that are
> part of a primary key.
> ...
> and pga1.attnum = i.indkey[pga2.attnum-1];

This is wrong because you are looking at only one indkey position, and
the attribute could be in any position of the primary key. I think
what you want is to drop pga2 from the query and instead use something
like

... and pga1.attnum in (i.indkey[0], i.indkey[1], i.indkey[2], ...)

(carrying it out to whatever you think is a reasonable upper bound on
the number of columns in a primary key --- the normal Postgres limit
is 32 keys but I can't believe anyone would use that many in practice).

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bengali 2003-08-15 16:27:36 [Newbie] migrating a stored procedure from MSSQL to postgresql
Previous Message Tim Andersen 2003-08-15 14:38:53 Re: About primary keys.