diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-10-02 23:50:16 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-10-02 23:50:16 +0000 |
commit | aa731ed8433914641e42f32fec0fcf27f01aab7e (patch) | |
tree | 7120217579cb1a88552c7a1ee44cc0a0749d6e3e /src/backend/commands/tablecmds.c | |
parent | 1b61ee3c69ccd869bddc56ae1021797a517ca9b7 (diff) | |
download | postgresql-aa731ed8433914641e42f32fec0fcf27f01aab7e.tar.gz postgresql-aa731ed8433914641e42f32fec0fcf27f01aab7e.zip |
Change nextval and other sequence functions to specify their sequence
argument as a 'regclass' value instead of a text string. The frontend
conversion of text string to pg_class OID is now encapsulated as an
implicitly-invocable coercion from text to regclass. This provides
backwards compatibility to the old behavior when the sequence argument
is explicitly typed as 'text'. When the argument is just an unadorned
literal string, it will be taken as 'regclass', which means that the
stored representation will be an OID. This solves longstanding problems
with renaming sequences that are referenced in default expressions, as
well as new-in-8.1 problems with renaming such sequences' schemas or
moving them to another schema. All per recent discussion.
Along the way, fix some rather serious problems in dbmirror's support
for mirroring sequence operations (int4 vs int8 confusion for instance).
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 63 |
1 files changed, 1 insertions, 62 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b3d0e017f15..b2877cebb76 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.171 2005/09/24 22:54:36 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.172 2005/10/02 23:50:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -168,8 +168,6 @@ static void AlterIndexNamespaces(Relation classRel, Relation rel, static void AlterSeqNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, const char *newNspName); -static void RebuildSerialDefaultExpr(Relation rel, AttrNumber attnum, - const char *seqname, const char *nspname); static int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids); static int transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, @@ -6313,15 +6311,6 @@ AlterSeqNamespaces(Relation classRel, Relation rel, */ AlterTypeNamespaceInternal(RelationGetForm(seqRel)->reltype, newNspOid, false); - /* - * And we need to rebuild the column default expression that - * relies on this sequence. - */ - if (depForm->refobjsubid > 0) - RebuildSerialDefaultExpr(rel, - depForm->refobjsubid, - RelationGetRelationName(seqRel), - newNspName); /* Now we can close it. Keep the lock till end of transaction. */ relation_close(seqRel, NoLock); @@ -6332,56 +6321,6 @@ AlterSeqNamespaces(Relation classRel, Relation rel, relation_close(depRel, AccessShareLock); } -/* - * Rebuild the default expression for a SERIAL column identified by rel - * and attnum. This is annoying, but we have to do it because the - * stored expression has the schema name as a text constant. - * - * The caller must be sure the specified column is really a SERIAL column, - * because no further checks are done here. - */ -static void -RebuildSerialDefaultExpr(Relation rel, AttrNumber attnum, - const char *seqname, const char *nspname) -{ - char *qstring; - A_Const *snamenode; - FuncCall *funccallnode; - RawColumnDefault *rawEnt; - - /* - * Create raw parse tree for the updated column default expression. - * This should match transformColumnDefinition() in parser/analyze.c. - */ - qstring = quote_qualified_identifier(nspname, seqname); - snamenode = makeNode(A_Const); - snamenode->val.type = T_String; - snamenode->val.val.str = qstring; - funccallnode = makeNode(FuncCall); - funccallnode->funcname = SystemFuncName("nextval"); - funccallnode->args = list_make1(snamenode); - funccallnode->agg_star = false; - funccallnode->agg_distinct = false; - - /* - * Remove any old default for the column. We use RESTRICT here for - * safety, but at present we do not expect anything to depend on the - * default. - */ - RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, false); - - /* Do the equivalent of ALTER TABLE ... SET DEFAULT */ - rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault)); - rawEnt->attnum = attnum; - rawEnt->raw_default = (Node *) funccallnode; - - /* - * This function is intended for CREATE TABLE, so it processes a - * _list_ of defaults, but we just do one. - */ - AddRelationRawConstraints(rel, list_make1(rawEnt), NIL); -} - /* * This code supports |