pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
find the sequence name from schema, table, field
3+ messages / 2 participants
[nested] [flat]

* find the sequence name from schema, table, field
@ 2008-01-10 07:29 johnf <jfabiani@yolo.com>
  2008-01-10 14:12 ` Re: find the sequence name from schema, table, field Alvaro Herrera <alvherre@commandprompt.com>
  0 siblings, 1 reply; 3+ messages in thread

From: johnf @ 2008-01-10 07:29 UTC (permalink / raw)
  To: 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: find the sequence name from schema, table, field
  2008-01-10 07:29 find the sequence name from schema, table, field johnf <jfabiani@yolo.com>
@ 2008-01-10 14:12 ` Alvaro Herrera <alvherre@commandprompt.com>
  2008-01-10 15:12   ` Re: find the sequence name from schema, table, field johnf <jfabiani@yolo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Alvaro Herrera @ 2008-01-10 14:12 UTC (permalink / raw)
  To: johnf <jfabiani@yolo.com>; +Cc: pgsql-admin

johnf wrote:

> 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).

pg_get_serial_sequence()

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: find the sequence name from schema, table, field
  2008-01-10 07:29 find the sequence name from schema, table, field johnf <jfabiani@yolo.com>
  2008-01-10 14:12 ` Re: find the sequence name from schema, table, field Alvaro Herrera <alvherre@commandprompt.com>
@ 2008-01-10 15:12   ` johnf <jfabiani@yolo.com>
  0 siblings, 0 replies; 3+ messages in thread

From: johnf @ 2008-01-10 15:12 UTC (permalink / raw)
  To: pgsql-admin

On Thursday 10 January 2008 06:12:43 am Alvaro Herrera wrote:
> pg_get_serial_sequence

But it only works with a serial data type.  

Create a sequence "mySequence"
Create a field "myField smallint NOT NULL  DEFAULT 
nextval('mysequence'::regclass)"

So given the name of the table and the name of the field. How can I find the 
name of the associated squence?



-- 
John Fabiani



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2008-01-10 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-01-10 07:29 find the sequence name from schema, table, field johnf <jfabiani@yolo.com>
2008-01-10 14:12 ` Alvaro Herrera <alvherre@commandprompt.com>
2008-01-10 15:12   ` johnf <jfabiani@yolo.com>

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