Skip to content

Commit 94da2a6

Browse files
committed
Use RangeVarGetRelidExtended() in AlterSequence()
This allows us to combine the opening and the ownership check. Reported-by: Robert Haas <robertmhaas@gmail.com>
1 parent 41839b7 commit 94da2a6

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/backend/commands/sequence.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,13 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
429429
HeapTuple seqtuple;
430430
HeapTuple newdatatuple;
431431

432-
/* Open and lock sequence. */
433-
relid = RangeVarGetRelid(stmt->sequence,
434-
ShareRowExclusiveLock,
435-
stmt->missing_ok);
432+
/* Open and lock sequence, and check for ownership along the way. */
433+
relid = RangeVarGetRelidExtended(stmt->sequence,
434+
ShareRowExclusiveLock,
435+
stmt->missing_ok,
436+
false,
437+
RangeVarCallbackOwnsRelation,
438+
NULL);
436439
if (relid == InvalidOid)
437440
{
438441
ereport(NOTICE,
@@ -443,11 +446,6 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
443446

444447
init_sequence(relid, &elm, &seqrel);
445448

446-
/* allow ALTER to sequence owner only */
447-
if (!pg_class_ownercheck(relid, GetUserId()))
448-
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
449-
stmt->sequence->relname);
450-
451449
rel = heap_open(SequenceRelationId, RowExclusiveLock);
452450
seqtuple = SearchSysCacheCopy1(SEQRELID,
453451
ObjectIdGetDatum(relid));

src/test/regress/expected/sequence.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ DROP SEQUENCE myseq2;
307307
ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
308308
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
309309
NOTICE: relation "sequence_test2" does not exist, skipping
310-
ALTER SEQUENCE pg_class CYCLE; -- error, not a sequence
311-
ERROR: "pg_class" is not a sequence
310+
ALTER SEQUENCE serialTest1 CYCLE; -- error, not a sequence
311+
ERROR: "serialtest1" is not a sequence
312312
CREATE SEQUENCE sequence_test2 START WITH 32;
313313
CREATE SEQUENCE sequence_test4 INCREMENT BY -1;
314314
SELECT nextval('sequence_test2');

src/test/regress/sql/sequence.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ DROP SEQUENCE myseq2;
172172
ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
173173
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
174174

175-
ALTER SEQUENCE pg_class CYCLE; -- error, not a sequence
175+
ALTER SEQUENCE serialTest1 CYCLE; -- error, not a sequence
176176

177177
CREATE SEQUENCE sequence_test2 START WITH 32;
178178
CREATE SEQUENCE sequence_test4 INCREMENT BY -1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy