FAQ
I am using Postgresql 7.2.4 and php 4.2.2 to write some generic
functions to access and manipulate all tables in a database.

I have been looking for a way to identify the primary key defined in a
table. The closest I have found is a filed in the pg_class table that
is a boolean that tells me if that table has or every had a primary
key.

So given the table name is there a way to identify the column defined as
the primary key for that table?

--
Scot L. Harris <webid@cfl.rr.com>

Search Discussions

  • Tom Lane at Jun 1, 2004 at 7:23 pm

    "Scot L. Harris" <webid@cfl.rr.com> writes:
    So given the table name is there a way to identify the column defined as
    the primary key for that table?
    You need to look in pg_index.

    Note that the primary key could be a multicolumn index, so starting with
    the assumption that there is "the column" is going to lead you on the
    wrong track.

    regards, tom lane

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-general @
categoriespostgresql
postedJun 1, '04 at 5:50p
activeJun 1, '04 at 7:23p
posts2
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Scot L. Harris: 1 post Tom Lane: 1 post

People

Translate

site design / logo © 2022 Grokbase