How to detect primary key of a table
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>:
Show quoted text
\d your_table
will show itcreate table foobar ( foo int primary key, bar int );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"foobar_pkey" for table "foobar"
CREATE TABLE\d foobar
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 tableHi, List!
I use PG8.1
Are there any abilities to detect primary key of a table?
Sergey Karin
Import Notes
Reply to msg id not found: 24F0604D7FD4E0438BF87420F044E394FC0BC2@D01S002.domain01.root.adsReference msg id not found: 24F0604D7FD4E0438BF87420F044E394FC0BC2@D01S002.domain01.root.ads | Resolved by subject fallback
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
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/interactive/catalogs.html
You could also query the Information Schema; table_constraints
joined with key_column_usage or constraint_column_usage should
yield a table's primary key columns.
http://www.postgresql.org/docs/8.1/interactive/information-schema.html
--
Michael Fuhr