[PATCH] Generate column names for subquery expressions - Mailing list pgsql-hackers

From Marti Raudsepp
Subject [PATCH] Generate column names for subquery expressions
Date
Msg-id CABRT9RCGKfCwOLCQEgo7O+jnOTro-oZB=j7E_qiA0s=x4AgaYA@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] Generate column names for subquery expressions
Re: [PATCH] Generate column names for subquery expressions
List pgsql-hackers
Hi list,

In current PostgreSQL versions, subquery expressions in the SELECT list always generate columns with name "?column?"

postgres=# select (select 1 as foo);
?column?
--------
       1

This patch improves on that:
  select (SELECT 1 AS foo) => foo
  select exists(SELECT 1)  => exists
  select array(SELECT 1)   => array

The "array" one is now consistent with an array literal: select array[1];

Other subquery types (=ALL(), =ANY() and row comparison) don't change because they act more like operators.

I guess it's fairly unlikely that users rely on column names being "?column?", but it does change the name of some expressions, for example:
  select (select 1 foo)::int;
  select case when true then 1 else (select 1 as foo) end;

Previously these returned column names "int4" and "case", now they would return "foo". Personally I prefer it this way, but if it is considered a compatibility problem, lowering the strength of subquery names in FigureColnameInternal would resort to the old behavior.

How this affects different queries can be seen from the regression diffs.

Does this sound like a good idea?
Should I submit this to the CommitFest?


Regards,
Marti Raudsepp

Attachment

pgsql-hackers by date:

Previous
From: Cédric Villemain
Date:
Subject: Re: postgresql.conf archive_command example
Next
From: Tom Lane
Date:
Subject: Re: Bogus nestloop join estimate, ignores WHERE clause