pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Bruce Momjian <bruce@momjian.us>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: 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: Sat, 21 Mar 2015 21:17:40 -0400
Message-ID: <20150322011740.GB10795@momjian.us> (raw )
In-Reply-To: <CAB7nPqSYiWJHPU6BG-rAA+fK7vRXNkHmpwzhgJJETjDGhmJuUg@mail.gmail.com >
References: <547F462E.8090001@gmail.com >
<19734.1417628674@sss.pgh.pa.us >
<20150321015254.GC13192@momjian.us >
<CAB7nPqSYiWJHPU6BG-rAA+fK7vRXNkHmpwzhgJJETjDGhmJuUg@mail.gmail.com >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Sat, Mar 21, 2015 at 04:27:45PM +0900, Michael Paquier wrote:
> On Sat, Mar 21, 2015 at 10:52 AM, Bruce Momjian <bruce@momjian.us> wrote:
> > Rather than fixing the docs, I implemented the feature --- patch
> > attached.
>
> A regression test would be welcome, in alter_table for example.
OK, regression test added in the attached patch.
--
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-bugs
Attachments:
alter.diff (text/x-diff, 3.1K) download
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
new file mode 100644
index 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.y
new file mode 100644
index 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
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
new file mode 100644
index 51db1b6..6a31df7
*** a/src/test/regress/expected/alter_table.out
--- b/src/test/regress/expected/alter_table.out
*************** Inherits: constraint_rename_test
*** 289,294 ****
--- 289,296 ----
DROP TABLE constraint_rename_test2;
DROP TABLE constraint_rename_test;
+ ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok
+ NOTICE: relation "constraint_not_exist" does not exist, skipping
ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
NOTICE: relation "constraint_rename_test" does not exist, skipping
-- FOREIGN KEY CONSTRAINT adding TEST
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
new file mode 100644
index d0d29ee..b5ee7b0
*** a/src/test/regress/sql/alter_table.sql
--- b/src/test/regress/sql/alter_table.sql
*************** ALTER TABLE constraint_rename_test RENAM
*** 228,233 ****
--- 228,234 ----
\d constraint_rename_test2
DROP TABLE constraint_rename_test2;
DROP TABLE constraint_rename_test;
+ ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok
ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
-- FOREIGN KEY CONSTRAINT adding TEST
view thread (7+ messages) latest in thread
Message-ID: <20150322011740.GB10795@momjian.us>
Permalink: ../20150322011740.GB10795@momjian.us/
Also on: postgresql.org/message-id/20150322011740.GB10795@momjian.us
copy link · copy postgr.es · copy git am
reply 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, michael.paquier@gmail.com, tgl@sss.pgh.pa.us, fhagur@gmail.com, osalm@mirakl.com
Subject: Re: ALTER TABLE documentation or parser bug
In-Reply-To: <20150322011740.GB10795@momjian.us>
References: <547F462E.8090001@gmail.com> <19734.1417628674@sss.pgh.pa.us> <20150321015254.GC13192@momjian.us> <CAB7nPqSYiWJHPU6BG-rAA+fK7vRXNkHmpwzhgJJETjDGhmJuUg@mail.gmail.com> <20150322011740.GB10795@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