From: Albert REINER <areiner@tph.tuwien.ac.at>
To: PostgreSQL-SQL <pgsql-sql@postgreSQL.org>
Subject: PL/pgSQL: returning array?
Date: Sat, 30 Dec 2000 12:20:42 +0100
Message-ID: <20001230122042.A1020@frithjof> (raw)
Saluton,
I am trying to write my first plpgsql-functions; I do not seem to
be able to find a way of returning an array; here is what I tried:
,----
| CREATE FUNCTION "concatallinstances2" (int4 ) RETURNS text[2] AS '
| declare
| reslt text;
| separator text;
| instance record;
| first text;
| begin
| reslt := '''';
| separator := '''';
| for instance in select cat from t where id = $1 order by cat LOOP
| if first is null then
| first := instance.cat;
| end if;
| reslt := reslt || separator || instance.cat;
| separator := '', '';
| end loop;
| return {first,reslt};
| end;
| ' LANGUAGE 'plpgsql';
`----
I also tried `... RETURNS text[] ...' and `... RETURNS text_ ...' (I
think I have read somewhere that the array type is given by basetype
plus underscore) - none of these seem to work.
I am using:
,----
| cgitest=> select version();
| version
| --------------------------------------------------------------------
| PostgreSQL 7.0.2 on i586-pc-linux-gnulibc1, compiled by gcc 2.95.1
| (1 row)
`----
I hope you can help me; thanks in advance -
Albert.
--
--------------------------------------------------------------------------
Albert Reiner <areiner@tph.tuwien.ac.at>
Deutsch * English * Esperanto * Latine
--------------------------------------------------------------------------
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: areiner@tph.tuwien.ac.at
Subject: Re: PL/pgSQL: returning array?
In-Reply-To: <20001230122042.A1020@frithjof>
References: <20001230122042.A1020@frithjof>
* 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