From: Joe Conway <mail@joeconway.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: Tue, 10 Aug 2004 10:41:46 -0700
Message-ID: <411908DA.6090305@joeconway.com> (raw)
In-Reply-To: <6C0CF58A187DA5479245E0830AF84F420803B2@poweredge.attiksystem.ch>
References: <6C0CF58A187DA5479245E0830AF84F420803B2@poweredge.attiksystem.ch>
Philippe Lang wrote:
> But the same query with a parameter returns an error:
>
> select id, usr, code, line1, line2 from tbl, get_lines(code);
> --> ERROR: function expression in FROM may not refer to other relations
> of same query level
This is as expected and required -- you cannot refer to other FROM
clause relations. I believe SQL99 defines a clause (LATERAL IIRC) that
would allow this, but it hasn't been implemented yet.
> Is there another way to run this query and get:
>
> id usr code line1 line2
> ----------------------------------
> 1 one 1 A B
> 2 two 2 Z Z
> 3 three 1 A B
Whats wrong with just using CASE:
select id, usr, code,
case when code = 1 then 'A' else 'Z' end as line1,
case when code = 1 then 'A' else 'Z' end as line2
from tbl;
id | usr | code | line1 | line2
----+-------+------+-------+-------
1 | one | 1 | A | A
2 | two | 2 | Z | Z
3 | three | 1 | A | A
(3 rows)
Joe
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: mail@joeconway.com, philippe.lang@attiksystem.ch
Subject: Re: function expression in FROM may not refer to other relations
In-Reply-To: <411908DA.6090305@joeconway.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