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

Re: returning array from function or "structured error"

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: returning array from function or "structured error"
Date: 2008-03-31 02:52:53
Message-ID: 47F05205.5010908@postnewspapers.com.au (view raw or flat)
Thread:
Lists: pgsql-general
Ivan Sergio Borgonovo wrote:
> Building up a temp table and returning a "setof record"
You can avoid the temp table and return `setof record'. Just `RETURN 
NEXT temp_result' after each test, where temp_result is your declared 
working variable. When you're done with all tests, do the final RETURN. 
No need for temp tables anywhere - your PHP invokes the function as 
`SELECT * FROM test_something(args)' and gets a normal resultset back, 
just as if it'd performed a SELECT from a table.

Personally, though I'd:

CREATE TYPE test_result AS (  test_id INTEGER, test_outcome TEXT );

or whatever's appropriate for your use, then declare the function as 
`RETURNS SETOF test_result'.

--
Craig Ringer

In response to

pgsql-general by date

Next:From: Tom LaneDate: 2008-03-31 03:03:14
Subject: Re: Logging/Viewing parameters of a prepared statement
Previous:From: Amit PhatarphekarDate: 2008-03-31 02:25:48
Subject: Logging/Viewing parameters of a prepared statement

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