Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime

From: Anthony Sotolongo <asotolongo(at)gmail(dot)com>
To: Rahila Syed <rahilasyed90(at)gmail(dot)com>
Cc: ketan(dot)bhatiya(at)lenditt(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19064: Trigger allows creation with invalid column references but fails at runtime
Date: 2025-09-26 13:35:50
Message-ID: CAASDfF2q2=2ehUq8+0wSQeYgzwjQmB=YHQ2C5_nDtiLQ9sxRgw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

From my point of view, this extension can help detect these types of
problems:

https://github.com/okbob/plpgsql_check

Regards

El vie, 26 sept 2025 a las 10:00, Rahila Syed (<rahilasyed90(at)gmail(dot)com>)
escribió:

> 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
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-09-26 14:53:26 Re: BUG #19066: postgresql-18.0/src/backend/optimizer/geqo/geqo_ox2.c:86: Array index check in wrong place ?
Previous Message Álvaro Herrera 2025-09-26 13:34:38 Re: TRAP: failed Assert("outerPlan != NULL") in postgres_fdw.c