PL/pgSQL: returning array?

From: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
To: PostgreSQL-SQL <pgsql-sql(at)postgreSQL(dot)org>
Subject: PL/pgSQL: returning array?
Date: 2000-12-30 11:20:42
Message-ID: 20001230122042.A1020@frithjof
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)tph(dot)tuwien(dot)ac(dot)at>
Deutsch * English * Esperanto * Latine
--------------------------------------------------------------------------

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas SMETS 2000-12-30 16:39:32 References to SERIAL
Previous Message Kaare Rasmussen 2000-12-30 10:45:38 Re: Date/Time problem -(((