How to detect primary key of a table
How to detect primary key of a table
От:
"Sergey Karin" <sergey.karin@gmail.com>
Дата:
Hi, List!
I use PG8.1
Are there any abilities to detect primary key of a table?
Sergey Karin
I use PG8.1
Are there any abilities to detect primary key of a table?
Sergey Karin
Re: How to detect primary key of a table
От:
"Sergey Karin" <sergey.karin@gmail.com>
Дата:
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
>> create 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 table
Hi, List!
I use PG8.1
Are there any abilities to detect primary key of a table?
Sergey Karin
Re: How to detect primary key of a table
От:
Tino Wildenhain <tino@wildenhain.de>
Дата:
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
Re: How to detect primary key of a table
От:
Michael Fuhr <mike@fuhr.org>
Дата:
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