Thread: PL/pgSQL: returning array?

PL/pgSQL: returning array?

From
"Albert REINER"
Date:
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
--------------------------------------------------------------------------