Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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
--------------------------------------------------------------------------

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group