Clarification on SET SESSION AUTHORIZATION Syntax

Started by PG Bug reporting form17 days ago6 messagesdocs

Thread notes

1 note#docs
hackorum-bot#docs
hackorum-bot
2 days ago

@global #docs

#docs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/18/sql-set-session-authorization.html
Description:

Hi Team,

In the `SET SESSION AUTHORIZATION` statement, the syntax is defined as:

```sql
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name;
```

I would like to clarify whether the following query is valid:

```sql
SET SESSION SESSION AUTHORIZATION user_name;
```

Since `SESSION` and `LOCAL` are optional alternatives in the syntax, does
the first `SESSION` keyword allow the query to contain two consecutive
`SESSION` keywords?

If this syntax is not valid, should we update the grammar to the following?

```sql
SET [ LOCAL ] SESSION AUTHORIZATION user_name;
```

Please clarify the expected syntax so that we can update the grammar
accordingly.

Thanks.

#2Matemática A3K
matematica.a3k@gmail.com
In reply to: PG Bug reporting form (#1)
Re: Clarification on SET SESSION AUTHORIZATION Syntax

On Thu, Nov 12, 2026 at 2:23 PM PG Doc comments form
<noreply@postgresql.org> wrote:

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/18/sql-set-session-authorization.html
Description:

Hi Team,

In the `SET SESSION AUTHORIZATION` statement, the syntax is defined as:

```sql
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name;
```

I would like to clarify whether the following query is valid:

```sql
SET SESSION SESSION AUTHORIZATION user_name;
```

~/code/pw main
❯ sudo -u postgres psql
[sudo] password for bot:
psql (18.6)
Type "help" for help.

postgres=# SET SESSION AUTHORIZATION 'paul';
ERROR: role "paul" does not exist
postgres=# SET SESSION SESSION AUTHORIZATION 'paul';
ERROR: role "paul" does not exist
postgres=# SET SESSION SESSION AUTHORIZATION 'postgres';
SET
postgres=# SET SESSION AUTHORIZATION 'postgres';
SET
postgres=# SET LOCAL SESSION AUTHORIZATION 'postgres';
WARNING: SET LOCAL can only be used in transaction blocks
SET

Since `SESSION` and `LOCAL` are optional alternatives in the syntax,

I first read it as "one or the other", but it is "one or the other or
none", as you may see from my console log

does
the first `SESSION` keyword allow the query to contain two consecutive
`SESSION` keywords?

If the question is "Is SET SESSION SESSION AUTHORIZATION 'user_name';
a valid statement?", then, yes. Otherwise, it is not clear to me.

If this syntax is not valid, should we update the grammar to the following?

```sql
SET [ LOCAL ] SESSION AUTHORIZATION user_name;
```

Please clarify the expected syntax so that we can update the grammar
accordingly.

The syntax is valid, no need to update that. The page makes more sense
after reading the SET one
(https://www.postgresql.org/docs/18/sql-set.html) linked,

After re-reading both, I wonder if a more appropriate syntax description is:
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION { user_name |
'user_name' | DEFAULT }
RESET SESSION AUTHORIZATION

Thanks.

Np

#3David G. Johnston
david.g.johnston@gmail.com
In reply to: Matemática A3K (#2)

On Thursday, November 12, 2026, Matemática A3K <matematica.a3k@gmail.com>
wrote:

SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name;

I first read it as "one or the other", but it is "one or the other or
none", as you may see from my console log

The square brackets are defined to mean optional in this scheme. It would
be { SESSION | LOCAL } if the choice were mandatory.

David J.

#4David G. Johnston
david.g.johnston@gmail.com
In reply to: Matemática A3K (#2)
Re: Clarification on SET SESSION AUTHORIZATION Syntax

On Thursday, November 12, 2026, Matemática A3K <matematica.a3k@gmail.com>
wrote:

After re-reading both, I wonder if a more appropriate syntax description
is:
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION { user_name |
'user_name' | DEFAULT }
RESET SESSION AUTHORIZATION

Yes, the difference there seems like a simple oversight.

David J.

#5Matemática A3K
matematica.a3k@gmail.com
In reply to: David G. Johnston (#4)
Re: Clarification on SET SESSION AUTHORIZATION Syntax

On Fri, Nov 13, 2026 at 12:32 AM David G. Johnston
<david.g.johnston@gmail.com> wrote:

On Thursday, November 12, 2026, Matemática A3K <matematica.a3k@gmail.com> wrote:

After re-reading both, I wonder if a more appropriate syntax description is:
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION { user_name |
'user_name' | DEFAULT }
RESET SESSION AUTHORIZATION

Yes, the difference there seems like a simple oversight.

Indeed! I tried changing the syntax to that and realized that I
couldn't rewrite the last paragraph of the description (woof! too
hard...). So, I only added the string literal referenced in the
description to the syntax.

Attaching the patch for completeness.

It makes sense to me to generate a bigger patch with all the patches
like this from time to time (let´s say, a month...), and commit it
with a subject like "doc: Monthly minor fixes". This way, small fixes
can get their way into the doc.

Do you think it would get approved?

Show quoted text

David J.

Attachments:

t258935_5
00001_doc_improve_set_authorization_syntax.patchtext/x-patch; charset=US-ASCII; name=00001_doc_improve_set_authorization_syntax.patchDownload+1-1
#6Fujii Masao
masao.fujii@gmail.com
In reply to: Matemática A3K (#5)
Re: Clarification on SET SESSION AUTHORIZATION Syntax

On Sat, Nov 14, 2026 at 11:59 AM Matemática A3K
<matematica.a3k@gmail.com> wrote:

So, I only added the string literal referenced in the
description to the syntax.

At least to me, adding the quoted form to the syntax summary seems
unnecessary. Because other commands, such as SET ROLE and SET,
also accept both identifiers and string literals, but their syntax summaries
in the docs don't explicitly show the quoted forms. Also the
SET SESSION AUTHORIZATION docs already states, "The user name can be
written as either an identifier or a string literal". Thought?

Regards,

--
Fujii Masao