BUG #18763: pg_get_viewdef returns an old def with new relation name

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: linyuzhe(dot)lyz(at)gmail(dot)com
Subject: BUG #18763: pg_get_viewdef returns an old def with new relation name
Date: 2025-01-02 06:43:57
Message-ID: 18763-92ec491c50111041@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18763
Logged by: lyz
Email address: linyuzhe(dot)lyz(at)gmail(dot)com
PostgreSQL version: 13.7
Operating system: Linux
Description:

in first connection

test5=# create table a1(c int);
CREATE TABLE
test5=# create table a2(c int);
CREATE TABLE
test5=# create view v as select * from a1;
CREATE VIEW

then rename relation names and replace view in one txn, but not commit.

test5=# begin;
BEGIN
test5=*# alter table a1 rename to a3;
ALTER TABLE
test5=*# alter table a2 rename to a1;
ALTER TABLE
test5=*# create or replace view v as select * from a1;
CREATE VIEW

in second connection:

test5=# select pg_get_viewdef('v');

it will be stuck by AccessShareLock of 'v'.

Then we commit txn in first connection,
the result of second connection wii be:

pg_get_viewdef
----------------
SELECT a3.c +
FROM a3;
(1 row)

old definition but using new relation name.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message 谭忠涛 2025-01-02 07:28:25 Incorrect sort result caused by ROLLUP and WHERE operation
Previous Message Noah Misch 2025-01-02 05:29:24 Re: Column changes such as an increase in varchar size, can cause extremely slow queries, and postgres should run analyze automatically.