pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedits posible to use a 2 column returning function as a subquery?
2+ messages / 2 participants
[nested] [flat]
* its posible to use a 2 column returning function as a subquery?
@ 2009-09-11 20:16 Gerardo Herzig <gherzig@fmed.uba.ar>
0 siblings, 1 reply; 2+ messages in thread
From: Gerardo Herzig @ 2009-09-11 20:16 UTC (permalink / raw)
To: pgsql-sql
Hi All. My poor english doest not allow me to get a better subject.
Here is the thing: I have a function who returns a two column result,
that is is used inside another function, like this
CREATE FUNCTION show_result((some args), OUT shoe varchar, OUT desc
varchar , OUT price numeric)
...
as
$$
select shoe,
(get_desc_and_price(shoe)).desc,
(get_desc_and_price(shoe)).price
from ...
$$ language sql;
This is the only way i get this thing working. According to the timming,
it looks like get_desc_and_price() is being called twice. There is some
syntax for calling get_desc_and_price only once?
As getting the 'description' and the 'price' share most of the logic, it
looks ok to write a single function that does the job.
Thanks!
Gerardo
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: its posible to use a 2 column returning function as a subquery?
@ 2009-09-11 21:44 Tom Lane <tgl@sss.pgh.pa.us>
parent: Gerardo Herzig <gherzig@fmed.uba.ar>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2009-09-11 21:44 UTC (permalink / raw)
To: Gerardo Herzig <gherzig@fmed.uba.ar>; +Cc: pgsql-sql
Gerardo Herzig <gherzig@fmed.uba.ar> writes:
> There is some syntax for calling get_desc_and_price only once?
Do something like
select (t).* from (select get_desc_and_price(shoe) as t from ...) ss;
If you don't have get_desc_and_price marked as volatile, you'll probably
also need to add "offset 0" to the sub-select to keep the planner from
flattening the sub-select and producing multiple calls of the function.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2009-09-11 21:44 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-09-11 20:16 its posible to use a 2 column returning function as a subquery? Gerardo Herzig <gherzig@fmed.uba.ar>
2009-09-11 21:44 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox