From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | "Roberto (SmartBit)" <roberto(at)smartbit(dot)inf(dot)br> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to get the primary key fields? |
Date: | 2002-10-18 20:19:52 |
Message-ID: | 3DB06CE8.4050302@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Roberto (SmartBit) wrote:
> Hi all
>
> how could I do a single select resulting a list of field name that are
> primary keys of a table??
>
In PostgreSQL 7.2.x (and I think in 7.1.x) you can use the plpgsql function
get_pk() located here:
http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=36
-----------------------------------------------------------------
-- Function: get_pk
-- Purpose: Retrieves a comma delimited
-- list of attribute names
-- making up the primary key
-- of the relation passed as argument $1
In 7.3 (now in beta), you can use dblink_get_pkey() from contrib/dblink.
Here's how it looks:
create table foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'foo_pkey' for
table 'foo'
-- list the primary key fields
select * from dblink_get_pkey('foo');
position | colname
----------+---------
1 | f1
2 | f2
(2 rows)
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Herbert Liechti | 2002-10-18 20:30:14 | Re: Migrating from Informix to Postgre |
Previous Message | Stephan Szabo | 2002-10-18 20:04:05 | Re: problem with transaction |