aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/system_views.sql6
-rw-r--r--src/backend/commands/sequence.c12
2 files changed, 5 insertions, 13 deletions
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index efb29adeb39..19cabc9a47f 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -176,11 +176,7 @@ CREATE VIEW pg_sequences AS
S.seqincrement AS increment_by,
S.seqcycle AS cycle,
S.seqcache AS cache_size,
- CASE
- WHEN has_sequence_privilege(C.oid, 'SELECT,USAGE'::text)
- THEN pg_sequence_last_value(C.oid)
- ELSE NULL
- END AS last_value
+ pg_sequence_last_value(C.oid) AS last_value
FROM pg_sequence S JOIN pg_class C ON (C.oid = S.seqrelid)
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE NOT pg_is_other_temp_schema(N.oid)
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index b4ad19c0539..9f28d40466b 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -1790,21 +1790,17 @@ pg_sequence_last_value(PG_FUNCTION_ARGS)
/* open and lock sequence */
init_sequence(relid, &elm, &seqrel);
- if (pg_class_aclcheck(relid, GetUserId(), ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("permission denied for sequence %s",
- RelationGetRelationName(seqrel))));
-
/*
* We return NULL for other sessions' temporary sequences. The
* pg_sequences system view already filters those out, but this offers a
* defense against ERRORs in case someone invokes this function directly.
*
* Also, for the benefit of the pg_sequences view, we return NULL for
- * unlogged sequences on standbys instead of throwing an error.
+ * unlogged sequences on standbys and for sequences for which the current
+ * user lacks privileges instead of throwing an error.
*/
- if (!RELATION_IS_OTHER_TEMP(seqrel) &&
+ if (pg_class_aclcheck(relid, GetUserId(), ACL_SELECT | ACL_USAGE) == ACLCHECK_OK &&
+ !RELATION_IS_OTHER_TEMP(seqrel) &&
(RelationIsPermanent(seqrel) || !RecoveryInProgress()))
{
Buffer buf;