Re: Dynamic Array into pl/pgSQL function - Mailing list pgsql-novice

From Oliver Elphick
Subject Re: Dynamic Array into pl/pgSQL function
Date
Msg-id 1086025894.27765.37.camel@linda
Whole thread Raw
In response to Re: Dynamic Array into pl/pgSQL function  (Oliver Elphick <olly@lfix.co.uk>)
Responses Re: Dynamic Array into pl/pgSQL function
List 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@lfix.co.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


pgsql-novice by date:

Previous
From: Oliver Elphick
Date:
Subject: Re: Dynamic Array into pl/pgSQL function
Next
From: "derrick"
Date:
Subject: Re: Dynamic Array into pl/pgSQL function