Re: Dynamic Array into pl/pgSQL function

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: derrick <derrick(at)grifflink(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Dynamic Array into pl/pgSQL function
Date: 2004-05-31 17:51:34
Message-ID: 1086025894.27765.37.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, 2004-05-31 at 18:31, Oliver Elphick wrote:
> In your original function definition, you declared the function as
> taking (varchar, varchar). I think that should be (varchar,
> varchar[]). If you haven't changed that, you are passing an array of
> varchars into a parameter that expects a scalar varchar.

Sorry, I saw that you had changed this.

Here is a simple example that works as a function:

junk=# CREATE OR REPLACE FUNCTION x(INTEGER[])
RETURNS SETOF INTEGER LANGUAGE 'plpgsql' AS '
DECLARE
i RECORD;
BEGIN
FOR i IN SELECT f1 FROM ci WHERE f1 = ANY ($1) LOOP
RETURN NEXT i.f1;
END LOOP;
RETURN;
END;';

junk=# select * from x('{1,2,3,4,5,6,7,8}');
x
---
2
6
1
8
(4 rows)

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"How precious also are thy thoughts unto me, O God! how
great is the sum of them! If I should count them, they
are more in number than the sand; when I awake, I am
still with thee." Psalms 139: 17,18

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message derrick 2004-05-31 23:15:50 Re: Dynamic Array into pl/pgSQL function
Previous Message Oliver Elphick 2004-05-31 17:31:53 Re: Dynamic Array into pl/pgSQL function