From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: ketan.bhatiya@lenditt.com
Subject: BUG #19064: Trigger allows creation with invalid column references but fails at runtime
Date: Fri, 26 Sep 2025 07:36:24 +0000
Message-ID: <19064-b896cfc12d4c7e75@postgresql.org> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, ketan.bhatiya@lenditt.com
Subject: Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime
In-Reply-To: <19064-b896cfc12d4c7e75@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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