Commit 94da2a6a authored by Peter Eisentraut's avatar Peter Eisentraut

Use RangeVarGetRelidExtended() in AlterSequence()

This allows us to combine the opening and the ownership check.
Reported-by: default avatarRobert Haas <robertmhaas@gmail.com>
parent 41839b7a
...@@ -429,10 +429,13 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt) ...@@ -429,10 +429,13 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
HeapTuple seqtuple; HeapTuple seqtuple;
HeapTuple newdatatuple; HeapTuple newdatatuple;
/* Open and lock sequence. */ /* Open and lock sequence, and check for ownership along the way. */
relid = RangeVarGetRelid(stmt->sequence, relid = RangeVarGetRelidExtended(stmt->sequence,
ShareRowExclusiveLock, ShareRowExclusiveLock,
stmt->missing_ok); stmt->missing_ok,
false,
RangeVarCallbackOwnsRelation,
NULL);
if (relid == InvalidOid) if (relid == InvalidOid)
{ {
ereport(NOTICE, ereport(NOTICE,
...@@ -443,11 +446,6 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt) ...@@ -443,11 +446,6 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
init_sequence(relid, &elm, &seqrel); 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); rel = heap_open(SequenceRelationId, RowExclusiveLock);
seqtuple = SearchSysCacheCopy1(SEQRELID, seqtuple = SearchSysCacheCopy1(SEQRELID,
ObjectIdGetDatum(relid)); ObjectIdGetDatum(relid));
......
...@@ -307,8 +307,8 @@ DROP SEQUENCE myseq2; ...@@ -307,8 +307,8 @@ DROP SEQUENCE myseq2;
ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24 ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE; INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
NOTICE: relation "sequence_test2" does not exist, skipping NOTICE: relation "sequence_test2" does not exist, skipping
ALTER SEQUENCE pg_class CYCLE; -- error, not a sequence ALTER SEQUENCE serialTest1 CYCLE; -- error, not a sequence
ERROR: "pg_class" is not a sequence ERROR: "serialtest1" is not a sequence
CREATE SEQUENCE sequence_test2 START WITH 32; CREATE SEQUENCE sequence_test2 START WITH 32;
CREATE SEQUENCE sequence_test4 INCREMENT BY -1; CREATE SEQUENCE sequence_test4 INCREMENT BY -1;
SELECT nextval('sequence_test2'); SELECT nextval('sequence_test2');
......
...@@ -172,7 +172,7 @@ DROP SEQUENCE myseq2; ...@@ -172,7 +172,7 @@ DROP SEQUENCE myseq2;
ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24 ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE; 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_test2 START WITH 32;
CREATE SEQUENCE sequence_test4 INCREMENT BY -1; CREATE SEQUENCE sequence_test4 INCREMENT BY -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment