pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: johnf <jfabiani@yolo.com>
To: pgsql-admin@postgresql.org
Subject: find the sequence name from schema, table, field
Date: Wed, 9 Jan 2008 23:29:31 -0800
Message-ID: <200801092329.31115.jfabiani@yolo.com> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <200801092329.31115.jfabiani@yolo.com>
Permalink:  ../200801092329.31115.jfabiani@yolo.com/
Also on:    postgresql.org/message-id/200801092329.31115.jfabiani@yolo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: jfabiani@yolo.com
  Subject: Re: find the sequence name from schema, table, field
  In-Reply-To: <200801092329.31115.jfabiani@yolo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox