Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

Next:From: derrickDate: 2004-05-31 23:15:50
Subject: Re: Dynamic Array into pl/pgSQL function
Previous:From: Oliver ElphickDate: 2004-05-31 17:31:53
Subject: Re: Dynamic Array into pl/pgSQL function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group