Re: Add column name to error description

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: jian he <jian.universality@gmail.com>
Cc: Erik Wienhold <ewie@ewie.name>, Marcos Pegoraro <marcos@f10.com.br>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-03-06T20:56:46Z
Lists: pgsql-hackers

Attachments

[ sorry about having let this thread fall off my radar ]

jian he <jian.universality@gmail.com> writes:
> if we print out NameStr(att->attname) then error becomes:
> +DETAIL:  Returned type unknown does not match expected type character
> varying in column "f2" (position 2).

> In this case,  printing out {column \"%s\"} is not helpful at all.

Actually, the problem is that we should be printing the expected
column name not the input column name.  At least in the test cases
we have, that gives a user-supplied name in every case.  Even if
there are some cases where you just get "f2", that's not horrible.
So I don't think this is worth the amount of code churn involved in
the v2 patch --- let's just print it unconditionally, as attached.
I do still think that including the column number is potentially
helpful, though, so I didn't remove that.

			regards, tom lane

Commits

  1. Include column name in build_attrmap_by_position's error reports.

  2. Instead of supposing (wrongly, in the general case) that the rowtype