| From: | George Silva <georger(dot)silva(at)gmail(dot)com> |
|---|---|
| To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
| Cc: | Devrim GÜNDÜZ <devrim(at)gunduz(dot)org>, PGSQL Mailing List <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Finding the primary key of tables |
| Date: | 2010-08-03 19:50:44 |
| Message-ID: | AANLkTikEG5ucZPpCZvZdhNE84eUQJOaKHWq-i3k_uyHU@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Thanks a million. Rusty SQL :P
2010/8/3 Merlin Moncure <mmoncure(at)gmail(dot)com>
> 2010/8/3 George Silva <georger(dot)silva(at)gmail(dot)com>:
> > 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
>
--
George R. C. Silva
Desenvolvimento em GIS
http://blog.geoprocessamento.net
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David Kerr | 2010-08-03 19:52:57 | Re: Question about Idle in TX |
| Previous Message | Merlin Moncure | 2010-08-03 19:50:03 | Re: Finding the primary key of tables |