Returning composite types from a plpgsql function

From: Joseph Barillari <jbarilla(at)princeton(dot)edu>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Returning composite types from a plpgsql function
Date: 2002-05-03 21:24:40
Message-ID: m3offwaprb.fsf@washer.barillari.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I've read in the mailing list archives that plpgsql does not support
assignment to array variables, so it is impossible to use them to
return data from a plpgsql function.

I'm curious as to how one might return more than one base type from
such a function, short of creating a temporary table and inserting the
value into that. For example:

CREATE TABLE tmp (a INTEGER, b INTEGER); --define the type

CREATE OR REPLACE FUNCTION frob()
RETURNS tmp AS '
DECLARE
ret tmp%ROWTYPE;
BEGIN
ret.a := 1;
ret.b := 2;
return ret;
END;'
LANGUAGE 'plpgsql';

Unfortunately, when I execute this, I get:

cal=> select frob();
frob
-----------
172795360
(1 row)

Is there some sort of type coercion I have to do to get this to work?

Thanks,

Joe

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2002-05-03 21:59:03 Re: Odd behavior with timestamp/interval arithmetic
Previous Message Joseph Barillari 2002-05-03 20:38:14 Odd behavior with timestamp/interval arithmetic