function returning setof..select versus select * from - Mailing list pgsql-general

From Jeff Amiel
Subject function returning setof..select versus select * from
Date
Msg-id 753432.21663.qm@web65511.mail.ac4.yahoo.com
Whole thread Raw
Responses Re: function returning setof..select versus select * from  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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?





pgsql-general by date:

Previous
From: Jeff Amiel
Date:
Subject: Frustrated...pg_dump/restore
Next
From: "Eduardo Arévalo"
Date:
Subject: postgres/postgis