Add column name to error description

Marcos Pegoraro <marcos@f10.com.br>

From: Marcos Pegoraro <marcos@f10.com.br>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-03-31T13:22:15Z
Lists: pgsql-hackers

Attachments

This is my first patch, so sorry if I miss something.

If I have a function which returns lots of columns and any of these columns
returns a wrong type it's not easy to see which one is that column because
it points me only to its position, not its name. So, this patch only adds
that column name, just that.

create function my_f(a integer, b integer) returns table(first_col integer,
lots_of_cols_later numeric) language plpgsql as $function$
begin
  return query select a, b;
end;$function$;

select * from my_f(1,1);
--ERROR: structure of query does not match function result type
--Returned type integer does not match expected type numeric in column 2.

For a function which has just 2 columns is easy but if it returns a hundred
of columns, which one is that 66th column ?

My patch just adds column name to that description message.
--ERROR: structure of query does not match function result type
--Returned type integer does not match expected type numeric in column 2-
lots_of_cols_later.

regards
Marcos

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