Re: proposal: row_to_array function - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: row_to_array function
Date
Msg-id CAFj8pRA8yo9-MSV0vmaG8Xd7x3NryB=8ZQXRidzsXTrrnU8fYA@mail.gmail.com
Whole thread Raw
In response to Re: proposal: row_to_array function  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Responses Re: proposal: row_to_array function
List pgsql-hackers


2015-01-26 21:44 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:
On 1/25/15 4:23 AM, Pavel Stehule wrote:

I tested a concept iteration over array in format [key1, value1, key2, value2, .. ] - what is nice, it works for [[key1,value1],[key2, value2], ...] too

It is only a few lines more to current code, and this change doesn't break a compatibility.

Do you think, so this patch is acceptable?

Ideas, comments?

Aside from fixing the comments... I think this needs more tests on corner cases. For example, what happens when you do

foreach a, b, c in array(array(1,2),array(3,4)) ?

it is relative simple behave -- empty values are NULL

array(1,2),array(3,4) -- do you think ARRAY[[1,2],[3,4]] is effectively ARRAY[1,2,3,4]
 

Or the opposite case of

foreach a,b in array(array(1,2,3))

Also, what about:

foreach a,b in '{{{1,2},{3,4}},{{5,6},{7,8}}}'::int[] ?


 postgres=# select array(select unnest('{{{1,2},{3,4}},{{5,6},{7,8}}}'::int[]));
       array       
-------------------
 {1,2,3,4,5,6,7,8}
(1 row)

so it generate pairs {1,2}{3,4},{5,6},{7,8}

Regards

Pavel Stehule


--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: proposal: searching in array function - array_position
Next
From: Robert Haas
Date:
Subject: Re: basebackups during ALTER DATABASE ... SET TABLESPACE ... not safe?