BUG #19069: pg_advisory_xact_lock() in a WITH query doesn't work

PG Bug reporting form <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: m.walczak@megavision.pl
Date: 2025-10-02T13:11:37Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      19069
Logged by:          Maciej Walczak
Email address:      m.walczak@megavision.pl
PostgreSQL version: 18.0
Operating system:   Windows 11 Pro 24H2
Description:        

This doesn't actually do any locking:

BEGIN;
WITH my_lock AS (
        SELECT pg_advisory_xact_lock(1)
)
INSERT INTO my_table (...) VALUES (...);
COMMIT;

To reproduce just run this code in two sessions in parallel without
commiting.
Both inserts will immediately complete without blocking.

I'm not sure if this is a bug. If it's not, perhaps the documentation should
be clarified.
Side-effects of WITH queries are mentioned here, so I would expect my code
to work:
https://www.postgresql.org/docs/16/queries-with.html#QUERIES-WITH-CTE-MATERIALIZATION

Tested on Postgres 18.0 and 16.10.