From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Philippe Lang <philippe(dot)lang(at)attiksystem(dot)ch> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: function expression in FROM may not refer to other relations |
Date: | 2004-08-12 14:36:37 |
Message-ID: | 20040812073151.G56533@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 that
select 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Pradeepkumar, Pyatalo (IE10) | 2004-08-12 14:47:06 | how to cast localtimestamp to bigint??? |
Previous Message | Tom Lane | 2004-08-12 14:30:41 | Re: function expression in FROM may not refer to other relations of same query level |