Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id E3BAC2E2F63 for ; Thu, 10 Jan 2008 03:29:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 04257-09 for ; Thu, 10 Jan 2008 03:29:26 -0400 (AST) Received: from mtao04.charter.net (mtao04.charter.net [209.225.8.178]) by postgresql.org (Postfix) with ESMTP id AF5A52E34E6 for ; Thu, 10 Jan 2008 03:29:33 -0400 (AST) Received: from aarprv06.charter.net ([10.20.200.76]) by mtao04.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20080110072932.VXLY10642.mtao04.charter.net@aarprv06.charter.net> for ; Thu, 10 Jan 2008 02:29:32 -0500 Received: from suse10-1.site ([68.186.33.18]) by aarprv06.charter.net with ESMTP id <20080110072931.TZBE14098.aarprv06.charter.net@suse10-1.site> for ; Thu, 10 Jan 2008 02:29:31 -0500 From: johnf To: pgsql-admin@postgresql.org Subject: find the sequence name from schema, table, field Date: Wed, 9 Jan 2008 23:29:31 -0800 User-Agent: KMail/1.9.6 (enterprise 20070904.708012) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200801092329.31115.jfabiani@yolo.com> X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/97 X-Sequence-Number: 27871 Hi, I have to go to the well and ask you guys how in the he_l I can determine t= he=20 sequence name if I only have the schema name (normally 'public'), the table= =20 name, and the field name (normally the PK). Below is the current SQL I'm=20 using but it does not account for field data types that are not 'serial'. = =20 IOW if the sequence name I'm looking for is not associated with a field whi= ch=20 has 'serial' for a data type it does not find the sequence name. =46rom a python script """SELECT seq.relname::text FROM pg_class src, pg_class seq, pg_namespace, pg_attribute, pg_depend WHERE pg_depend.refobjsubid =3D pg_attribute.attnum AND pg_depend.refobjid =3D src.oid AND seq.oid =3D pg_depend.objid AND src.relnamespace =3D pg_namespace.oid AND pg_attribute.attrelid =3D src.oid AND pg_namespace.nspname =3D '%s' AND src.relname =3D '%s' AND pg_attribute.attname =3D '%s'""" %=20 (localSchemaName,localTableName,cursor.KeyField) Thanks in advance for any help you may provide! =2D-=20 John Fabiani