Commit d13f372a authored by Tom Lane's avatar Tom Lane

Fix pg_get_serial_sequence(), which could incorrectly return the name

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.
parent 792d6edd
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ruleutils.c - Functions to convert stored expressions/querytrees * ruleutils.c - Functions to convert stored expressions/querytrees
* back to source text * 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" #include "postgres.h"
...@@ -1288,12 +1288,14 @@ pg_get_serial_sequence(PG_FUNCTION_ARGS) ...@@ -1288,12 +1288,14 @@ pg_get_serial_sequence(PG_FUNCTION_ARGS)
Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup); Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
/* /*
* We assume any auto dependency of a relation on a column must be * We assume any auto dependency of a sequence on a column must be
* what we are looking for. * what we are looking for. (We need the relkind test because indexes
* can also have auto dependencies on columns.)
*/ */
if (deprec->classid == RelationRelationId && if (deprec->classid == RelationRelationId &&
deprec->objsubid == 0 && deprec->objsubid == 0 &&
deprec->deptype == DEPENDENCY_AUTO) deprec->deptype == DEPENDENCY_AUTO &&
get_rel_relkind(deprec->objid) == RELKIND_SEQUENCE)
{ {
sequenceId = deprec->objid; sequenceId = deprec->objid;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment