On Aug 6, 2010, at 10:15 PM, Pavel Stehule wrote:
>> This is not exactly without precedent, either: our built-in xpath()
>> function appears to use precisely this approach for its namespace-list
>> argument.
>
> it's one variant, but isn't perfect
>
> a) it expects so key and value are literals
Huh? You can select into an array:
try=# create table foo(k text, v text);
CREATE TABLE
try=# insert into foo values ('foo', 'bar'), ('baz', 'yow');
INSERT 0 2
try=# select ARRAY[k,v] FROM foo; array
-----------{foo,bar}{baz,yow}
(2 rows)
try=# select ARRAY(SELECT ARRAY[k,v] FROM foo);
ERROR: could not find array type for datatype text[]
Okay, so nested arrays are harder.
> b) it expects so all values has same types - what is usually what we
> need, but not necessary
The XML interface converts them all to text anyway, no?
> c) isn't too readable - I am sorry so I am repeating - it is same
> reason, why people will prefer a VARIADIC function before function
> with array - but I can accept, so this is my view of world
I agree that it's not as sugary as pairs would be. But I admit to having no problem with
SELECT foo(ARRAY[ ['foo', 'bar'], ['baz', 'yow']]);
But maybe I'm biased, since there's a lot of that sort of syntax in pgTAP.
Best,
David