From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Flavio Henrique Araque Gurgel <fhagur@gmail.com>
Cc: pgsql-bugs@postgresql.org
Cc: osalm@mirakl.com
Subject: Re: ALTER TABLE documentation or parser bug
Date: Fri, 20 Mar 2015 21:52:54 -0400
Message-ID: <20150321015254.GC13192@momjian.us> (raw)
In-Reply-To: <19734.1417628674@sss.pgh.pa.us>
References: <547F462E.8090001@gmail.com>
<19734.1417628674@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Wed, Dec 3, 2014 at 12:44:34PM -0500, Tom Lane wrote:
> Flavio Henrique Araque Gurgel <fhagur@gmail.com> writes:
> > Hello all
> > In the documentation in:
> > http://www.postgresql.org/docs/current/static/sql-altertable.html
>
> > It says that, to rename a constraint, we can use:
>
> > ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
> > RENAME CONSTRAINT constraint_name TO new_constraint_name
>
> > Who is wrong, parser or documentation (or myself)?
>
> Documentation, evidently: a look at the grammar shows that IF EXISTS has
> been implemented only for a rather haphazard subset of ALTER ... RENAME
> cases, and this isn't one of them.
Rather than fixing the docs, I implemented the feature --- patch
attached.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ Everyone has their own god. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:alter.diff (text/x-diff, 1.8K) downloaddiff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cnew file mode 100644index 4147457..ad81995
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
*************** RenameConstraint(RenameStmt *stmt)
*** 2496,2504 ****
{
/* lock level taken here should match rename_constraint_internal */
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
! false, false,
RangeVarCallbackForRenameAttribute,
NULL);
}
return
--- 2496,2511 ----
{
/* lock level taken here should match rename_constraint_internal */
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
! stmt->missing_ok, false,
RangeVarCallbackForRenameAttribute,
NULL);
+ if (!OidIsValid(relid))+ {+ ereport(NOTICE,+ (errmsg("relation \"%s\" does not exist, skipping",+ stmt->relation->relname)));+ return InvalidObjectAddress;+ }
}
return
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.ynew file mode 100644index 82405b9..4dc9d7f
*** a/src/backend/parser/gram.y
--- b/src/backend/parser/gram.y
*************** RenameStmt: ALTER AGGREGATE func_name ag
*** 7692,7697 ****
--- 7692,7708 ----
n->relation = $3;
n->subname = $6;
n->newname = $8;
+ n->missing_ok = false;+ $$ = (Node *)n;+ }+ | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name+ {+ RenameStmt *n = makeNode(RenameStmt);+ n->renameType = OBJECT_TABCONSTRAINT;+ n->relation = $5;+ n->subname = $8;+ n->newname = $10;+ n->missing_ok = true;
$$ = (Node *)n;
}
| ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, fhagur@gmail.com, osalm@mirakl.com
Subject: Re: ALTER TABLE documentation or parser bug
In-Reply-To: <20150321015254.GC13192@momjian.us>
References: <547F462E.8090001@gmail.com> <19734.1417628674@sss.pgh.pa.us> <20150321015254.GC13192@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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