Home > Archive > PostgreSQL Discussion > March 2006 > How to detect primary key of a table









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to detect primary key of a table
Sergey Karin

2006-03-30, 7:30 am

Hi, List!

I use PG8.1

Are there any abilities to detect primary key of a table?

Sergey Karin

Sergey Karin

2006-03-30, 7:30 am

Yes, it is not a problem via psql.

But I want to detect primary key via libpq (e.g using select commands)


2006/3/30, Michael Kleiser <Michael.Kleiser@combots.com>:
>
> \d your_table
> will show it
>
>
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
> "foobar_pkey" for table "foobar"
> CREATE TABLE
>
> Table "public.foobar"
> Column | Type | Modifiers
> --------+---------+-----------
> foo | integer | not null
> bar | integer |
> Indexes:
> "foobar_pkey" PRIMARY KEY, btree (foo)
>
> ____________________
____________
>
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Sergey Karin
> Sent: Thursday, March 30, 2006 1:13 PM
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] How to detect primary key of a table
>
>
> Hi, List!
>
> I use PG8.1
>
> Are there any abilities to detect primary key of a table?
>
> Sergey Karin
>
>


Tino Wildenhain

2006-03-30, 7:30 am

Sergey Karin schrieb:
>
> Yes, it is not a problem via psql.
>
> But I want to detect primary key via libpq (e.g using select commands)
>

Look into informational-schema
or start psql with the option -e
then use \d+ and see what it prints :-)

Regards
Tino

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Michael Fuhr

2006-03-30, 7:30 am

On Thu, Mar 30, 2006 at 03:13:12PM +0400, Sergey Karin wrote:
> Are there any abilities to detect primary key of a table?


In psql you could use "\d tablename". To see the queries that psql
makes, execute "\set ECHO_HIDDEN" and then "\d tablename". Here's
the documentation for the system catalogs that psql queries:

http://www.postgresql.org/docs/8.1/...e/catalogs.html

You could also query the Information Schema; table_constraints
joined with key_column_usage or constraint_column_us
age should
yield a table's primary key columns.

http://www.postgresql.org/docs/8.1/...ion-schema.html

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com