From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | ketan(dot)bhatiya(at)lenditt(dot)com |
Subject: | BUG #19064: Trigger allows creation with invalid column references but fails at runtime |
Date: | 2025-09-26 07:36:24 |
Message-ID: | 19064-b896cfc12d4c7e75@postgresql.org |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19064
Logged by: Ketan Bhatiya
Email address: ketan(dot)bhatiya(at)lenditt(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2025-09-26 09:14:08 | Re: Issue with PostgreSQL 18.0 Docker image volume mount (/var/lib/postgresql/data symlink) |
Previous Message | Pavel Hushcha | 2025-09-26 05:53:09 | Issue with PostgreSQL 18.0 Docker image volume mount (/var/lib/postgresql/data symlink) |