Search Postgresql Archives

Re: Finding the primary key of tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/8/3 George Silva <georger.silva@xxxxxxxxx>:
> I'm going for Merlin's solution. Its the easiest one :P
>
> But I'm also having a problem:
>
> SELECT column_name FROM information_schema.key_column_usage k
>     LEFT OUTER JOIN information_schema.table_constraints ON (k.table_name =
> table_constraints.table_name)
> WHERE
>         table_constraints.constraint_type = 'PRIMARY KEY'
>         AND k.table_name = 'acidentes'
>         AND k.table_schema = 'public'
>
> this still returns me multiple columns. Did I forgot something?

yup -- you are supposed be matching on constraint_name, not just
table_name. try:
 SELECT column_name FROM information_schema.key_column_usage k
     LEFT OUTER JOIN information_schema.table_constraints USING
(table_schema, table_name, constraint_name)
 WHERE
         table_constraints.constraint_type = 'PRIMARY KEY'
         AND k.table_name = 'acidentes'
         AND k.table_schema = 'public'


merlin

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux