Christian von Kietzell <chris@gammu.ath.cx> writes:
> Suppose, I've got the table shown above. I've only got its name. What
> I want is the column name the primary key is created on. How can I do
> that? Basically, which of foo_pkey and foo_data is the primary key?
You poke around in the system catalogs. Look in pg_index for a row that
describes an index on your table (join indrelid to pg_class.oid) and has
indisprimary true. (If no such row, there's no primary key.) Then look
in pg_attribute to get the column name(s) based on the column numbers
you see in indkey. See
http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/catalog-pg-index.html
regards, tom lane