Re: Function use in query - Mailing list pgsql-general

From David Johnston
Subject Re: Function use in query
Date
Msg-id 1370549878872-5758201.post@n5.nabble.com
Whole thread Raw
In response to Re: Function use in query  (Ioana Danes <ioanasoftware@yahoo.ca>)
List pgsql-general
Ioana Danes wrote
> create view tmp_view as
> with func as (
>     select tmp_Cashdrawer.CashdrawerID, test1(tmp_Cashdrawer.CashdrawerID)
> as call
>     from tmp_Cashdrawer
> )
> select func.CashdrawerID, (func.call).*
> from func;

So yeah, putting this into a view will not work.  The WITH/CTE construct is
an optimization barrier so the WHERE clause that is going to be used cannot
be applied before the function call is performed - only afterwards.

As I said before LATERAL in 9.3 may help - though others will have to
comment - in cleaning up the syntax and multiple-calls.

For <= 9.2 you will have to either live with the slightly verbose syntax or
wrap what you need into user-defined functions.

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Function-use-in-query-tp5758051p5758201.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Jeff Janes
Date:
Subject: Re: Database performs massive reads when I'm doing writes.
Next
From: Ray Cote
Date:
Subject: Re: Database performs massive reads when I'm doing writes.