Re: proposal: row_to_array function

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: row_to_array function
Date: 2015-01-18 19:30:46
Message-ID: CAFj8pRAec3CV_ShO49D=f1=wAyDUsvxFXuu6d9vcHsbBEEXY-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2015-01-17 7:26 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
> 2015-01-16 22:35 GMT+01:00 Andrew Dunstan <andrew(at)dunslane(dot)net>:
>
>>
>> On 01/16/2015 12:22 PM, Pavel Stehule wrote:
>>
>>>
>>>
>>> There two possible transformations:
>>>
>>> row_to_array --> [[key1, value1],[key2, value2], ...]
>>> row_to_row_array --> [(key1, value1), (key2, value2), ... ]
>>>
>>>
>>> If we're going to go that route, I think it makes more sense to
>>> create an actual key/value type (ie:
>>> http://pgxn.org/dist/pair/doc/pair.html) and return an array of
>>> that.
>>>
>>>
>>> ok
>>>
>>> <http://BlueTreble.com>
>>>
>>>
>>
>> I think we'd possibly be better off with simply returning a flat array,
>> [key1, value1, ...]
>>
>> Thats's what the hstore(text[]) and json_object(text[]) functions accept,
>> along with the 2D variant, if we want a precedent.
>>
>
> It can be one of supported variant. I should not be one, because we cannot
> to simply iterate over it
>
> Next possibility is teach FOREACH to take key and value in one step.
>

I looked to code and iteration over pair (key, value) is more simple

FOREACH supports target list, but source should be composite array.

ostgres=# do $$
declare a int;
b int;
begin
foreach a,b in array ARRAY[(1,2),(3,4)]
loop
raise notice 'a = %, b = %', a,b;
end loop;
end;
$$ language plpgsql;
NOTICE: a = 1, b = 2
NOTICE: a = 3, b = 4
DO

Conversion from ARRAY[k1,v1,k2,v2, ... ] is not well consistent with
current design

>
> Regards
>
> Pavel
>
>
>>
>> cheers
>>
>> andrew
>>
>>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-01-18 21:09:29 Re: Re: Better way of dealing with pgstat wait timeout during buildfarm runs?
Previous Message Noah Misch 2015-01-18 18:19:33 Re: Better way of dealing with pgstat wait timeout during buildfarm runs?