variadic array arguments, can it work?

From: Ingmar Brouns <swingi(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: variadic array arguments, can it work?
Date: 2012-01-19 15:56:32
Message-ID: CA+77E=ZkVMSr+E5vbdGb61QTB+odf2hF=kfJvtzfr+1KhhJ2vg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I was trying to write a variadic function where the arguments themselves
are arrays, but calling it does not seem to work. I couldn't find
documentation mentioning this restriction

postgres=# create or replace function foo(variadic args integer[][])
returns integer
as $$
begin return args[2][2]; end;
$$ language plpgsql;

Now I can call the function using variadic:

postgres=# select foo(variadic array[array[1,2],array[3,4]]);
foo
-----
4
(1 row)

but I cannot call it in the normal way...

postgres=# select foo( array[1,2] , array[3,4] );
ERROR: function foo(integer[], integer[]) does not exist at character 8
HINT: No function matches the given name and argument types. You might
need to add explicit type casts.
STATEMENT: select foo( array[1,2] , array[3,4] );
ERROR: function foo(integer[], integer[]) does not exist
LINE 1: select foo( array[1,2] , array[3,4] );
^
HINT: No function matches the given name and argument types. You might
need to add explicit type casts.

I suspect this has to do something with multiple dimensional arrays not
truly being arrays of arrays...

Kind regards,

Ingmar Brouns

version

----------------------------------------------------------------------------------------------------------
----
PostgreSQL 9.1.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.6.1
20110908 (Red Hat 4.6.1-9), 64-
bit
(1 row)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-01-19 16:06:33 Re: variadic array arguments, can it work?
Previous Message Florian Weimer 2012-01-19 14:54:29 Re: On duplicate ignore