]> granicus.if.org Git - postgresql/commitdiff
Fix pg_get_serial_sequence(), which could incorrectly return the name
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Nov 2006 22:59:29 +0000 (22:59 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Nov 2006 22:59:29 +0000 (22:59 +0000)
of an index on a serial column, rather than the name of the associated
sequence.  Fallout from recent changes in dependency setup for serials.
Per bug #2732 from Basil Evseenko.

src/backend/utils/adt/ruleutils.c

index f5b42524be7810e89a280a28bc018b2445ad8a2b..9d9404bde4c481cd68fe4858ab30cc6ddb5f7e09 100644 (file)
@@ -2,7 +2,7 @@
  * ruleutils.c - Functions to convert stored expressions/querytrees
  *                             back to source text
  *
- *       $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.234 2006/10/04 00:29:59 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.235 2006/11/10 22:59:29 tgl Exp $
  **********************************************************************/
 
 #include "postgres.h"
@@ -1288,12 +1288,14 @@ pg_get_serial_sequence(PG_FUNCTION_ARGS)
                Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
 
                /*
-                * We assume any auto dependency of a relation on a column must be
-                * what we are looking for.
+                * We assume any auto dependency of a sequence on a column must be
+                * what we are looking for.  (We need the relkind test because indexes
+                * can also have auto dependencies on columns.)
                 */
                if (deprec->classid == RelationRelationId &&
                        deprec->objsubid == 0 &&
-                       deprec->deptype == DEPENDENCY_AUTO)
+                       deprec->deptype == DEPENDENCY_AUTO &&
+                       get_rel_relkind(deprec->objid) == RELKIND_SEQUENCE)
                {
                        sequenceId = deprec->objid;
                        break;