pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Sawtell <csawtell@xtra.co.nz>
To: Jie Liang <jliang@ipinc.com>
To: Sveinung Haslestad <sveinung.haslestad@swipnet.se>
Cc: pgsql-sql@postgresql.org
Subject: Re: Array as parameter in plpgSQL functions
Date: Thu, 1 Mar 2001 21:41:58 +1300
Message-ID: <01030121415800.31527@berty> (raw)
In-Reply-To: <Pine.BSF.4.10.10101311240550.50465-100000@tidal.ipinc.com>
References: <Pine.BSF.4.10.10101311240550.50465-100000@tidal.ipinc.com>

On Thu, 01 Feb 2001 09:47, Jie Liang wrote:
> e.g.
>
> create function foo(_int4) returns int2 as'
> declare
> a _int4 alias for $1;
> i int:=1;
> begin
> while a[i] loop
> i:=i+1;
> end loop;
> return i-1;
> end;
> ' language 'plpgsql';
>
> you can call it by:
>
> select foo('{1232131,12312321,3424234}');
>
> you should get 3.

In order to get it to work I had to alter it very slightly vis:-

chris=# create function array_element_count(_int4) returns integer as '
chris'#  declare
chris'#   a alias for $1;
chris'#   i integer;
chris'#  begin
chris'#   i := 1;
chris'#   while a[i] loop
chris'#    i := i+1;
chris'#   end loop;
chris'#  return i-1;
chris'#  end;' language 'plpgsql' with(isstrict,iscachable);
CREATE
chris=# select 
array_element_count('{59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,8
7}');
 array_element_count
---------------------
                  29
(1 row)                                                                    
                                                 

-- 
Sincerely etc.,

 NAME       Christopher Sawtell
 CELL PHONE 021 257 4451
 ICQ UIN    45863470
 EMAIL      csawtell @ xtra . co . nz
 CNOTES     ftp://ftp.funet.fi/pub/languages/C/tutorials/sawtell_C.tar.gz

 -->> Please refrain from using HTML or WORD attachments in e-mails to me 
<<--




view thread (3+ messages)

Message-ID: <01030121415800.31527@berty>
Permalink:  ../01030121415800.31527@berty/
Also on:    postgresql.org/message-id/01030121415800.31527@berty

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: csawtell@xtra.co.nz, jliang@ipinc.com, sveinung.haslestad@swipnet.se
  Subject: Re: Array as parameter in plpgSQL functions
  In-Reply-To: <01030121415800.31527@berty>
  References: <Pine.BSF.4.10.10101311240550.50465-100000@tidal.ipinc.com> <01030121415800.31527@berty>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox