Funny behavior in event trigger code with CREATE OR REPLACE VIEW and column additions

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Funny behavior in event trigger code with CREATE OR REPLACE VIEW and column additions
Date: 2026-02-27 07:25:41
Message-ID: aaFG9bqkEn0RhLJG@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

While removing some dust from my stack of patches, I have bumped into
a weird interaction with CREATE OR REPLACE VIEW due to
AT_AddColumnToView:
CREATE VIEW one_view AS SELECT * FROM one;
-- Adds some columns.
CREATE OR REPLACE VIEW one_view AS SELECT * FROM one, two;

The funny behavior is with the second VIEW query, that has the idea to
stack twice a ViewStmt in event triggers: once in a
EventTriggerCollectSimpleCommand() and a second time in
EventTriggerAlterTableEnd(). Now, why would the second one be
stacked? Well, EventTriggerAlterTableEnd() would add it because it
has some AT_AddColumnToView subcommands.

First, I was wondering if we should tweak EventTriggerAlterTableEnd()
so as subcommands that add columns to a view should not be duplicated,
applying some filtering. However, at the end, I have come to accept
the fact that event triggers are a representation at SQL level of the
internal structures of these commands. Hence, the current code is
fine, still we had better have some tests to document that. And we
don't do that now.

This issue has come up while looking at a portion of my sequence AM
patch, where I was not sure what the right representation should be in
event triggers. I just noticed that column additions for views do
already the same thing.

So, please find attached a small-ish patch to close the gap with a few
tests:
- One thing for event_trigger.sql, with column additions for view, to
check the collection.
- One for test_ddl_deparse, that shows the stack of both a "simple"
and an "alter table".

Thoughts or comments?
--
Michael

Attachment Content-Type Size
0001-Add-tests-for-CREATE-OR-REPLACE-VIEW-with-column-add.patch text/plain 4.7 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-02-27 07:33:24 Re: Defects with invalid stats data for expressions in extended stats
Previous Message Chao Li 2026-02-27 06:51:40 Re: Defects with invalid stats data for expressions in extended stats