Re: unintuitive subquery record wrapping

From: Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com>
To: Rikard Pavelic <rikard(dot)pavelic(at)zg(dot)htnet(dot)hr>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: unintuitive subquery record wrapping
Date: 2010-09-18 13:22:41
Message-ID: AANLkTinrO27iFse+w+ma9kOixXO4ayTDNbMj96V-8rxq@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Sep 18, 2010 at 12:40 PM, Rikard Pavelic
<rikard(dot)pavelic(at)zg(dot)htnet(dot)hr> wrote:
> On 18.9.2010 11:36, Arjen Nienhuis wrote:
>> I'm not sure what you want but maybe it's this:
>>
>>
>> => select * from (select t from t) sq;
>>    t
>> -------
>>  (1,x)
>> (1 row)
>>
>> => select (sq.t).* from (select t from t) sq;
>>  a | b
>> ---+---
>>  1 | x
>> (1 row)
>>
>>
>
> I know how to expand record to type or set by hand. That's not the issue.
> I'm just trying to understand if changing type of record when alias is
> different is intentional decision or unintentional.
> Because, if it's unintentional, I would like it to get fixed
> (I guess I'll have to take a look at the code if nobody answers me).
>
> I don't see any benefit in loosing type info because variable alias
> don't match.

It's not the alias. Subqueries are typed as "record". I think thats
because there is little difference between these:

(SELECT * FROM t)
(SELECT a, b FROM t)
(SELECT a + 1, b FROM t)
(SELECT 1, b FROM t)

Which of these should have type "t"?

You need to do this:

SELECT x FROM t x;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-09-18 15:50:23 Re: unintuitive subquery record wrapping
Previous Message Rikard Pavelic 2010-09-18 10:40:03 Re: unintuitive subquery record wrapping