find the sequence name from schema, table, field

From: johnf <jfabiani(at)yolo(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: find the sequence name from schema, table, field
Date: 2008-01-10 07:29:31
Message-ID: 200801092329.31115.jfabiani@yolo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,
I have to go to the well and ask you guys how in the he_l I can determine the
sequence name if I only have the schema name (normally 'public'), the table
name, and the field name (normally the PK). Below is the current SQL I'm
using but it does not account for field data types that are not 'serial'.
IOW if the sequence name I'm looking for is not associated with a field which
has 'serial' for a data type it does not find the sequence name.

From a python script
"""SELECT seq.relname::text
FROM pg_class src, pg_class seq, pg_namespace, pg_attribute,
pg_depend
WHERE
pg_depend.refobjsubid = pg_attribute.attnum AND
pg_depend.refobjid = src.oid AND
seq.oid = pg_depend.objid AND
src.relnamespace = pg_namespace.oid AND
pg_attribute.attrelid = src.oid AND
pg_namespace.nspname = '%s' AND
src.relname = '%s' AND
pg_attribute.attname = '%s'""" %
(localSchemaName,localTableName,cursor.KeyField)

Thanks in advance for any help you may provide!
--
John Fabiani

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Suresh Gupta VG 2008-01-10 07:37:09 Need some info.
Previous Message Bruce Momjian 2008-01-10 03:07:44 Re: pg_dumpall --exclude