I was checking some loose ends in SQL conformance, when I noticed: We support GRANT role ... GRANTED BY CURRENT_USER, but we don't support CURRENT_ROLE in that place, even though in PostgreSQL they are equivalent. Here is a trivial patch to add that.

--
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From f46554c2bba025b62b796748d3aa3a65fd080f7f Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 24 Jun 2020 08:21:48 +0200
Subject: [PATCH 1/2] Allow CURRENT_ROLE in GRANTED BY

This is specified in the SQL standard.  Since in PostgreSQL,
CURRENT_ROLE is equivalent to CURRENT_USER, and CURRENT_USER is
already supported here, adding CURRENT_ROLE is trivial.
---
 doc/src/sgml/ref/grant.sgml  | 1 +
 doc/src/sgml/ref/revoke.sgml | 1 +
 src/backend/parser/gram.y    | 4 ++++
 3 files changed, 6 insertions(+)

diff --git a/doc/src/sgml/ref/grant.sgml b/doc/src/sgml/ref/grant.sgml
index bc573f7826..fe231aa30c 100644
--- a/doc/src/sgml/ref/grant.sgml
+++ b/doc/src/sgml/ref/grant.sgml
@@ -87,6 +87,7 @@
 
     [ GROUP ] <replaceable class="parameter">role_name</replaceable>
   | PUBLIC
+  | CURRENT_ROLE
   | CURRENT_USER
   | SESSION_USER
 </synopsis>
diff --git a/doc/src/sgml/ref/revoke.sgml b/doc/src/sgml/ref/revoke.sgml
index b6bac21c57..b50f99dfe7 100644
--- a/doc/src/sgml/ref/revoke.sgml
+++ b/doc/src/sgml/ref/revoke.sgml
@@ -114,6 +114,7 @@
 
     [ GROUP ] <replaceable class="parameter">role_name</replaceable>
   | PUBLIC
+  | CURRENT_ROLE
   | CURRENT_USER
   | SESSION_USER
 </synopsis>
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e669d75a5a..6e6565dc26 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -14949,6 +14949,10 @@ RoleSpec:      NonReservedWord
                                                }
                                                $$ = n;
                                        }
+                       | CURRENT_ROLE
+                                       {
+                                               $$ = 
makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
+                                       }
                        | CURRENT_USER
                                        {
                                                $$ = 
makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
-- 
2.27.0

Reply via email to