BUG #19069: pg_advisory_xact_lock() in a WITH query doesn't work - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #19069: pg_advisory_xact_lock() in a WITH query doesn't work
Date
Msg-id 19069-f5c72e4e4f921a7c@postgresql.org
Whole thread Raw
Responses Re: BUG #19069: pg_advisory_xact_lock() in a WITH query doesn't work
List 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.


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19068: postgresql-server-dev-17 from apt.postgresql.org installs libpq-int.h for 18 version
Next
From: PG Bug reporting form
Date:
Subject: BUG #19070: issue with DETACH PARTITION CONCURRENTLY on a hash partition table