Thread

  1. [PATCH] Generate column names for subquery expressions

    Marti Raudsepp <marti@juffo.org> — 2011-08-31T22:36:53Z

    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