pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19064: Trigger allows creation with invalid column references but fails at runtime
4+ messages / 4 participants
[nested] [flat]
* BUG #19064: Trigger allows creation with invalid column references but fails at runtime
@ 2025-09-26 07:36 PG Bug reporting form <noreply@postgresql.org>
2025-09-26 12:46 ` Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime David G. Johnston <david.g.johnston@gmail.com>
2025-09-26 12:59 ` Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime Rahila Syed <rahilasyed90@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: PG Bug reporting form @ 2025-09-26 07:36 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: ketan.bhatiya@lenditt.com
The following bug has been logged on the website:
Bug reference: 19064
Logged by: Ketan Bhatiya
Email address: ketan.bhatiya@lenditt.com
PostgreSQL version: Unsupported/Unknown
Operating system: Windows
Description:
Example Function & Trigger
CREATE OR REPLACE FUNCTION update_order_total()
RETURNS TRIGGER AS $$
BEGIN
-- Wrong column reference: "wrong_column" does not exist in "Orders"
UPDATE Orders
SET total = NEW.wrong_column
WHERE id = NEW.id;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER trg_update_order_total
AFTER UPDATE ON Orders
FOR EACH ROW
EXECUTE FUNCTION update_order_total();
Steps to Reproduce
Run the above function and trigger creation.
✅ They are created successfully.
Update a row in Orders.
Expected Result
If the trigger contains a reference to a non-existing column, PostgreSQL
should throw an error at creation time.
Actual Result
The function and trigger creation succeed.
❌ At runtime, when an update happens, it fails with:
ERROR: record "new" has no field "wrong_column"
Suggestion / Proposed Improvement
PostgreSQL should validate column references at trigger creation time, not
just at runtime.
If a column does not exist in the target table (Orders in this example),
trigger creation should fail immediately with a clear error message.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime
2025-09-26 07:36 BUG #19064: Trigger allows creation with invalid column references but fails at runtime PG Bug reporting form <noreply@postgresql.org>
@ 2025-09-26 12:46 ` David G. Johnston <david.g.johnston@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: David G. Johnston @ 2025-09-26 12:46 UTC (permalink / raw)
To: ketan.bhatiya@lenditt.com <ketan.bhatiya@lenditt.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Friday, September 26, 2025, PG Bug reporting form <noreply@postgresql.org>
wrote:
> The following bug has been logged on the website:
>
> Bug reference: 19064
> Logged by: Ketan Bhatiya
> Email address: ketan.bhatiya@lenditt.com
> PostgreSQL version: Unsupported/Unknown
> Operating system: Windows
> Description:
>
> Suggestion / Proposed Improvement
> PostgreSQL should validate column references at trigger creation time, not
> just at runtime.
> If a column does not exist in the target table (Orders in this example),
> trigger creation should fail immediately with a clear error message.
>
>
The bug reporting list should not be used for feature requests. Those
should be directed to -general.
It seems unlikely anyone is going to spend time on this though. You are
expected to test what you write and this fails immediately and obviously.
David J.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime
2025-09-26 07:36 BUG #19064: Trigger allows creation with invalid column references but fails at runtime PG Bug reporting form <noreply@postgresql.org>
@ 2025-09-26 12:59 ` Rahila Syed <rahilasyed90@gmail.com>
2025-09-26 13:35 ` Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime Anthony Sotolongo <asotolongo@gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: Rahila Syed @ 2025-09-26 12:59 UTC (permalink / raw)
To: ketan.bhatiya@lenditt.com; pgsql-bugs@lists.postgresql.org
Hi
> Suggestion / Proposed Improvement
> PostgreSQL should validate column references at trigger creation time, not
> just at runtime.
> If a column does not exist in the target table (Orders in this example),
> trigger creation should fail immediately with a clear error message.
>
>
This behaviour is by design in PostgreSQL. The CreateTrigger() is
responsible
for creating a dependency between trigger and its underlying pl/pgsql
function.
The pl/pgsql function is only parsed when it is executed for the first time.
This approach allows for flexibility, such as adding columns to a table
after a trigger
has been created. On the other hand, if a column existing at the time of
trigger creation
is later removed, validating at creation time would not offer much
advantage in these
situations.
Thank you,
Rahila Syed
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime
2025-09-26 07:36 BUG #19064: Trigger allows creation with invalid column references but fails at runtime PG Bug reporting form <noreply@postgresql.org>
2025-09-26 12:59 ` Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime Rahila Syed <rahilasyed90@gmail.com>
@ 2025-09-26 13:35 ` Anthony Sotolongo <asotolongo@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Anthony Sotolongo @ 2025-09-26 13:35 UTC (permalink / raw)
To: Rahila Syed <rahilasyed90@gmail.com>; +Cc: ketan.bhatiya@lenditt.com; pgsql-bugs@lists.postgresql.org
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2025-09-26 13:35 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-09-26 07:36 BUG #19064: Trigger allows creation with invalid column references but fails at runtime PG Bug reporting form <noreply@postgresql.org>
2025-09-26 12:46 ` David G. Johnston <david.g.johnston@gmail.com>
2025-09-26 12:59 ` Rahila Syed <rahilasyed90@gmail.com>
2025-09-26 13:35 ` Anthony Sotolongo <asotolongo@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox