Re: function expression in FROM may not refer to other relations - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: function expression in FROM may not refer to other relations
Date
Msg-id 20040812073151.G56533@megazone.bigpanda.com
Whole thread Raw
In response to Re: function expression in FROM may not refer to other relations of same query level  ("Philippe Lang" <philippe.lang@attiksystem.ch>)
List pgsql-sql
On Thu, 12 Aug 2004, Philippe Lang wrote:

> > > The problem now is that get_lines is being called twice per line.
> >
> > Is get_lines() defined as IMMUTABLE?  Should it be?
>
> I have tried defining get_lines as "IMMUTABLE", or "WITH (iscachable)",
> but it keeps on getting called twice per line in the following query...
>
> select
>   id,
>   usr,
>   code,
>   (get_lines(code)).line1,
>   (get_lines(code)).line2
> from tbl;
>
> I wish there was a way to run the query like this:
>
> select
>   id,
>   usr,
>   code,
>   CAST(get_lines(code) as lines)
> from tbl;

Note thatselect id, usr, code, get_lines(code) from tbl;
should work in 8.0beta although you get the composite type as
the last column, not two columns.

sszabo=# select id, usr, code, get_lines(code) from tbl;id |  usr  | code | get_lines
----+-------+------+----------- 1 | one   |    1 | (A,B) 2 | two   |    2 | (Z,Z) 3 | three |    1 | (A,B)
(3 rows)

You can get individual columns with a bit of work and a subselect in from
but you need to trick the system to not pull up the subselect to not get
the function called twice per row.



pgsql-sql by date:

Previous
From: "Pradeepkumar, Pyatalo (IE10)"
Date:
Subject: how to cast localtimestamp to bigint???
Next
From: Oliver Elphick
Date:
Subject: Re: Sending errors from psql to error file