Re: Functions that return RECORD type - Mailing list pgsql-general

From Richard Huxton
Subject Re: Functions that return RECORD type
Date
Msg-id 41E790DC.3010907@archonet.com
Whole thread Raw
In response to Functions that return RECORD type  ("Craig Bryden" <postgresql@bryden.co.za>)
List pgsql-general
Craig Bryden wrote:
> When I run     select * from GetAccountInfo (100)    I get the following
> error message: ERROR:  a column definition list is required for functions
> returning "record"
>
> please can someone explain to me how to create a column definition list.

CREATE FUNCTION foo() RETURNS SETOF RECORD AS
'SELECT 1::int,2::int,''A''::text;'
LANGUAGE sql;

SELECT * FROM foo() AS (a int, b int, c text);
  a | b | c
---+---+---
  1 | 2 | A
(1 row)

The other way (which I prefer) is to define a type and change the
function definition:

CREATE TYPE foo_res_type AS (a int, b int, c text);
CREATE FUNCTION foo() RETURNS SETOF foo_res_type ...

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Bo Lorentsen
Date:
Subject: Re: OID Usage
Next
From: Christian Kratzer
Date:
Subject: Re: OID Usage