Re: Show expression of virtual columns in error messages

From: "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com>
To: "Yugo Nagata" <nagata(at)sraoss(dot)co(dot)jp>
Cc: "Peter Eisentraut" <peter(at)eisentraut(dot)org>, <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Show expression of virtual columns in error messages
Date: 2026-02-06 12:25:04
Message-ID: DG7VKZO7JWBK.3JZ1PZ7EA8C8S@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri Feb 6, 2026 at 12:54 AM -03, Yugo Nagata wrote:
>> >> Another possibility would be to get the actual values of "a" for example
>> >> and show it on the error message, e.g:
>> >>
>> >> ERROR: new row for relation "t" violates check constraint "t_c_check"
>> >> DETAIL: Failing row contains (5, 10, 5 * 2).
>> >
>> > That would indeed be more useful. One way to achieve this might be to
>> > modify deparse_context and get_variable() so that a Var is displayed as its
>> > actual value.
>> >
>> I'm not sure if I understand how modifying deparse_context_for() could
>> help on this.
>>
>> What I did was to use the expression_tree_mutator API to mutate the
>> virtual column expression to replace any Var reference with the value
>> into the TupleTableSlot. Please see the attached v2 version.
>
> I initially thought about having deparse_context_for() directly output
> actual values for Var references, but that does not seem like a good
> approach. Replacing Vars with Consts beforehand using
> expression_tree_mutator, as you did, looks like a better solution.
>
> One thing I noticed is that some expressions in virtual columns (e.g.,
> NULL and negative integers) differ from those in normal columns, for
> example in the following (null vs. NULL):
>
> +DETAIL: Failing row contains (null, NULLIF(NULL::integer, 0)).
>
> However, this seems acceptable.
>
Yeah, after parsing we don't have the original string representation of
the parse node, so at deparse_expression() it has it's own style to
deparse nodes. I don't think that it's an issue and I also think that
it's accepttable.

> Overall, this patch looks good to me.
>
Thank you for reviewing the patch!

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-02-06 12:37:13 Re: [PATCH] Support automatic sequence replication
Previous Message Christoph Berg 2026-02-06 12:21:09 Re: [PATCH] Add last_executed timestamp to pg_stat_statements