Returning composite types from a plpgsql function - Mailing list pgsql-sql

From Joseph Barillari
Subject Returning composite types from a plpgsql function
Date
Msg-id m3offwaprb.fsf@washer.barillari.org
Whole thread Raw
Responses Re: Returning composite types from a plpgsql function  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-sql by date:

Previous
From: Joseph Barillari
Date:
Subject: Odd behavior with timestamp/interval arithmetic
Next
From: Tom Lane
Date:
Subject: Re: Returning composite types from a plpgsql function