function returning setof..select versus select * from

From: "Jeff Amiel" <JAmiel(at)istreamimaging(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: function returning setof..select versus select * from
Date: 2008-10-02 19:32:15
Message-ID: C17A452040EDB84AA7A10AEA334E3E1455D225@AD1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What is the difference between:

select foo();
and
select * from foo();

Foo is defined as:

CREATE OR REPLACE FUNCTION foo()
RETURNS SETOF integer AS
'SELECT column from foo_table;'
LANGUAGE 'sql' STABLE;

Explain shows difference...

explain select * from foo()
"Function Scan on foo (cost=0.00..1.25 rows=1000 width=4)"

Explain select foo();
"Result (cost=0.00..0.00 rows=1 width=0)"

They both return the same results..yet yield different plans...and
different speeds when using 'real' data.

Why come?

Browse pgsql-general by date

  From Date Subject
Next Message Frank Durstewitz, Emporis GmbH 2008-10-02 19:39:34 Re: Trigger disable for table
Previous Message Gurjeet Singh 2008-10-02 17:40:17 Re: Transactions within a function body