functions are returns columns - Mailing list pgsql-sql

From Michele Petrazzo - Unipex srl
Subject functions are returns columns
Date
Msg-id 4734B921.5050704@unipex.it
Whole thread Raw
Responses Re: functions are returns columns  ("Pavel Stehule" <pavel.stehule@gmail.com>)
List pgsql-sql
Hi all.
I want that a function return a table rows (like the doc says at 33.4.4.
SQL Functions as Table Sources), but I want the a function return only a
few cols, so the same that I select into the func.
Modifying the doc example:

CREATE TABLE foo (fooid int, foosubid int, fooname text);
INSERT INTO foo VALUES (1, 1, 'Joe');
INSERT INTO foo VALUES (1, 2, 'Ed');
INSERT INTO foo VALUES (2, 1, 'Mary');

CREATE FUNCTION getfoo(int) RETURNS foo AS $$    SELECT fooid, foosubid FROM foo WHERE fooid = $1;
$$ LANGUAGE SQL;

This give me an error:

ERROR:  return type mismatch in function declared to return foo
DETAIL:  Final SELECT returns too few columns.
CONTEXT:  SQL function "getfoo"


So, how do it?

Thanks,
Michele


pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Select in From clause
Next
From: "Pavel Stehule"
Date:
Subject: Re: functions are returns columns