pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Array as parameter in plpgSQL functions
3+ messages / 3 participants
[nested] [flat]

* Array as parameter in plpgSQL functions
@ 2001-01-31 20:30  Sveinung Haslestad <sveinung.haslestad@swipnet.se>
  0 siblings, 1 reply; 3+ messages in thread

From: Sveinung Haslestad @ 2001-01-31 20:30 UTC (permalink / raw)
  To: pgsql-sql

I need to pass an array to a function ( int4, variable number of elements) .
How do i declare the parameter, and how can i tell the numer of recieved elements?

Thanks
/Sveinung







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Array as parameter in plpgSQL functions
@ 2001-01-31 20:47  Jie Liang <jliang@ipinc.com>
  parent: Sveinung Haslestad <sveinung.haslestad@swipnet.se>
  0 siblings, 1 reply; 3+ messages in thread

From: Jie Liang @ 2001-01-31 20:47 UTC (permalink / raw)
  To: Sveinung Haslestad <sveinung.haslestad@swipnet.se>; +Cc: pgsql-sql


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.

Jie LIANG

Internet Products Inc.

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang@ipinc.com
www.ipinc.com

On Wed, 31 Jan 2001, Sveinung Haslestad wrote:

> I need to pass an array to a function ( int4, variable number of elements) .
> How do i declare the parameter, and how can i tell the numer of recieved elements?
> 
> Thanks
> /Sveinung
> 
> 
> 
> 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Array as parameter in plpgSQL functions
@ 2001-03-01 08:41  Christopher Sawtell <csawtell@xtra.co.nz>
  parent: Jie Liang <jliang@ipinc.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Christopher Sawtell @ 2001-03-01 08:41 UTC (permalink / raw)
  To: Jie Liang <jliang@ipinc.com>; Sveinung Haslestad <sveinung.haslestad@swipnet.se>; +Cc: pgsql-sql

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 
<<--




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-03-01 08:41 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-01-31 20:30 Array as parameter in plpgSQL functions Sveinung Haslestad <sveinung.haslestad@swipnet.se>
2001-01-31 20:47 ` Jie Liang <jliang@ipinc.com>
2001-03-01 08:41   ` Christopher Sawtell <csawtell@xtra.co.nz>

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