selecting a attribute from a function
Dear all,
I have written a function that returns a set. This set is of a type I made, containing multiple attributes.
create type my_type as (col1 int, col2 int)
Something likes this works:
select col1 from my_pg_func('hello');
But how can I do something like this:
select my_pg_func(table2.some_col).col1
from table2.some_col
Yours,
Aarjan
On Thu, Nov 24, 2005 at 11:47:53AM +0100, A.j. Langereis wrote:
But how can I do something like this:
select my_pg_func(table2.some_col).col1
from table2.some_col
Use another set of parentheses around the function call, as at the
end of this example:
CREATE TYPE test_type AS (col1 integer, col2 integer);
CREATE FUNCTION test_func() RETURNS test_type AS $$
DECLARE
retval test_type;
BEGIN
retval.col1 := 123;
retval.col2 := 456;
RETURN retval;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM test_func();
col1 | col2
------+------
123 | 456
(1 row)
SELECT (test_func()).col1;
col1
------
123
(1 row)
--
Michael Fuhr