pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedALTER TABLE documentation or parser bug
7+ messages / 4 participants
[nested] [flat]
* ALTER TABLE documentation or parser bug
@ 2014-12-03 17:19 Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Re: ALTER TABLE documentation or parser bug Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 7+ messages in thread
From: Flavio Henrique Araque Gurgel @ 2014-12-03 17:19 UTC (permalink / raw)
To: pgsql-bugs; +Cc: osalm@mirakl.com
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
With the optionel "IF EXISTS".
When trying in a 9.3.5 server:
ALTER TABLE IF EXISTS foo RENAME CONSTRAINT fk_foo_bar TO fk_foo_din;
It returns an error:
ERROR: syntax error at or near "CONSTRAINT"
LINE 1: ALTER TABLE IF EXISTS shop rename CONSTRAINT fk_foo_bar...
If I try without "IF EXISTS" it works as expected.
Who is wrong, parser or documentation (or myself)?
Thanks
Flavio Gurgel
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: ALTER TABLE documentation or parser bug
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
@ 2014-12-03 17:44 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-03-21 01:52 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
0 siblings, 1 reply; 7+ messages in thread
From: Tom Lane @ 2014-12-03 17:44 UTC (permalink / raw)
To: Flavio Henrique Araque Gurgel <fhagur@gmail.com>; +Cc: pgsql-bugs; osalm@mirakl.com
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.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: ALTER TABLE documentation or parser bug
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Re: ALTER TABLE documentation or parser bug Tom Lane <tgl@sss.pgh.pa.us>
@ 2015-03-21 01:52 ` Bruce Momjian <bruce@momjian.us>
2015-03-21 07:27 ` Re: ALTER TABLE documentation or parser bug Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Bruce Momjian @ 2015-03-21 01:52 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Flavio Henrique Araque Gurgel <fhagur@gmail.com>; pgsql-bugs; osalm@mirakl.com
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-bugs
Attachments:
alter.diff (text/x-diff, 1.8K) 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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: ALTER TABLE documentation or parser bug
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Re: ALTER TABLE documentation or parser bug Tom Lane <tgl@sss.pgh.pa.us>
2015-03-21 01:52 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
@ 2015-03-21 07:27 ` Michael Paquier <michael.paquier@gmail.com>
2015-03-22 01:17 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
0 siblings, 1 reply; 7+ messages in thread
From: Michael Paquier @ 2015-03-21 07:27 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Flavio Henrique Araque Gurgel <fhagur@gmail.com>; pgsql-bugs; osalm@mirakl.com
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.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: ALTER TABLE documentation or parser bug
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Re: ALTER TABLE documentation or parser bug Tom Lane <tgl@sss.pgh.pa.us>
2015-03-21 01:52 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
2015-03-21 07:27 ` Re: ALTER TABLE documentation or parser bug Michael Paquier <michael.paquier@gmail.com>
@ 2015-03-22 01:17 ` Bruce Momjian <bruce@momjian.us>
2015-03-22 05:45 ` Re: ALTER TABLE documentation or parser bug Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Bruce Momjian @ 2015-03-22 01:17 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Flavio Henrique Araque Gurgel <fhagur@gmail.com>; pgsql-bugs; osalm@mirakl.com
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: ALTER TABLE documentation or parser bug
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Re: ALTER TABLE documentation or parser bug Tom Lane <tgl@sss.pgh.pa.us>
2015-03-21 01:52 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
2015-03-21 07:27 ` Re: ALTER TABLE documentation or parser bug Michael Paquier <michael.paquier@gmail.com>
2015-03-22 01:17 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
@ 2015-03-22 05:45 ` Michael Paquier <michael.paquier@gmail.com>
2015-03-24 23:53 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
0 siblings, 1 reply; 7+ messages in thread
From: Michael Paquier @ 2015-03-22 05:45 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Flavio Henrique Araque Gurgel <fhagur@gmail.com>; pgsql-bugs; osalm@mirakl.com
On Sun, Mar 22, 2015 at 10:17 AM, Bruce Momjian <bruce@momjian.us> wrote:
> 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.
That looks fine for me. Thanks!
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: ALTER TABLE documentation or parser bug
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Re: ALTER TABLE documentation or parser bug Tom Lane <tgl@sss.pgh.pa.us>
2015-03-21 01:52 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
2015-03-21 07:27 ` Re: ALTER TABLE documentation or parser bug Michael Paquier <michael.paquier@gmail.com>
2015-03-22 01:17 ` Re: ALTER TABLE documentation or parser bug Bruce Momjian <bruce@momjian.us>
2015-03-22 05:45 ` Re: ALTER TABLE documentation or parser bug Michael Paquier <michael.paquier@gmail.com>
@ 2015-03-24 23:53 ` Bruce Momjian <bruce@momjian.us>
0 siblings, 0 replies; 7+ messages in thread
From: Bruce Momjian @ 2015-03-24 23:53 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Flavio Henrique Araque Gurgel <fhagur@gmail.com>; pgsql-bugs; osalm@mirakl.com
On Sun, Mar 22, 2015 at 02:45:32PM +0900, Michael Paquier wrote:
> On Sun, Mar 22, 2015 at 10:17 AM, Bruce Momjian <bruce@momjian.us> wrote:
> > 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.
>
> That looks fine for me. Thanks!
Thanks, applied.
--
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
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2015-03-24 23:53 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-12-03 17:19 ALTER TABLE documentation or parser bug Flavio Henrique Araque Gurgel <fhagur@gmail.com>
2014-12-03 17:44 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-03-21 01:52 ` Bruce Momjian <bruce@momjian.us>
2015-03-21 07:27 ` Michael Paquier <michael.paquier@gmail.com>
2015-03-22 01:17 ` Bruce Momjian <bruce@momjian.us>
2015-03-22 05:45 ` Michael Paquier <michael.paquier@gmail.com>
2015-03-24 23:53 ` Bruce Momjian <bruce@momjian.us>
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