[PATCH] Generate column names for subquery expressions

From: Marti Raudsepp <marti(at)juffo(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Generate column names for subquery expressions
Date: 2011-08-31 22:36:53
Message-ID: CABRT9RCGKfCwOLCQEgo7O+jnOTro-oZB=j7E_qiA0s=x4AgaYA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
0001-Generate-column-names-for-subquery-expressions.patch text/x-patch 3.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-08-31 22:54:34 Re: Bogus nestloop join estimate, ignores WHERE clause
Previous Message Cédric Villemain 2011-08-31 22:17:18 Re: postgresql.conf archive_command example