Use RangeVarGetRelidExtended() in AlterSequence()
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 13 Jun 2017 18:58:17 +0000 (14:58 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 16 Jun 2017 14:24:50 +0000 (10:24 -0400)
This allows us to combine the opening and the ownership check.

Reported-by: Robert Haas <robertmhaas@gmail.com>
src/backend/commands/sequence.c
src/test/regress/expected/sequence.out
src/test/regress/sql/sequence.sql

index 2d820e5cebc859bfd9dfbdef4fcb5b0cfd46d870..031bbc874dea0af42cb17a7327614d755182baf4 100644 (file)
@@ -429,10 +429,13 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
    HeapTuple   seqtuple;
    HeapTuple   newdatatuple;
 
-   /* Open and lock sequence. */
-   relid = RangeVarGetRelid(stmt->sequence,
-                            ShareRowExclusiveLock,
-                            stmt->missing_ok);
+   /* Open and lock sequence, and check for ownership along the way. */
+   relid = RangeVarGetRelidExtended(stmt->sequence,
+                                    ShareRowExclusiveLock,
+                                    stmt->missing_ok,
+                                    false,
+                                    RangeVarCallbackOwnsRelation,
+                                    NULL);
    if (relid == InvalidOid)
    {
        ereport(NOTICE,
@@ -443,11 +446,6 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
 
    init_sequence(relid, &elm, &seqrel);
 
-   /* allow ALTER to sequence owner only */
-   if (!pg_class_ownercheck(relid, GetUserId()))
-       aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
-                      stmt->sequence->relname);
-
    rel = heap_open(SequenceRelationId, RowExclusiveLock);
    seqtuple = SearchSysCacheCopy1(SEQRELID,
                                   ObjectIdGetDatum(relid));
index 16c12f3434a05429d3e3619603da2fcadaee4b56..a43b52cfc1e6548a59b6e3cde01369102ac24c5e 100644 (file)
@@ -307,8 +307,8 @@ DROP SEQUENCE myseq2;
 ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
   INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
 NOTICE:  relation "sequence_test2" does not exist, skipping
-ALTER SEQUENCE pg_class CYCLE;  -- error, not a sequence
-ERROR:  "pg_class" is not a sequence
+ALTER SEQUENCE serialTest1 CYCLE;  -- error, not a sequence
+ERROR:  "serialtest1" is not a sequence
 CREATE SEQUENCE sequence_test2 START WITH 32;
 CREATE SEQUENCE sequence_test4 INCREMENT BY -1;
 SELECT nextval('sequence_test2');
index d53e33d779479d0f0a6a1e1d85915cd81ab83e6b..b41c5a753dc3d0bdc5374940e3330ff82658a962 100644 (file)
@@ -172,7 +172,7 @@ DROP SEQUENCE myseq2;
 ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
   INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
 
-ALTER SEQUENCE pg_class CYCLE;  -- error, not a sequence
+ALTER SEQUENCE serialTest1 CYCLE;  -- error, not a sequence
 
 CREATE SEQUENCE sequence_test2 START WITH 32;
 CREATE SEQUENCE sequence_test4 INCREMENT BY -1;