From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Philippe Lang <philippe.lang@attiksystem.ch>
Cc: pgsql-sql@postgresql.org
Subject: Re: function expression in FROM may not refer to other relations
Date: Thu, 12 Aug 2004 07:36:37 -0700 (PDT)
Message-ID: <20040812073151.G56533@megazone.bigpanda.com> (raw)
In-Reply-To: <6C0CF58A187DA5479245E0830AF84F420803B7@poweredge.attiksystem.ch>
References: <6C0CF58A187DA5479245E0830AF84F420803B7@poweredge.attiksystem.ch>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone.bigpanda.com, philippe.lang@attiksystem.ch
Subject: Re: function expression in FROM may not refer to other relations
In-Reply-To: <20040812073151.G56533@megazone.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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