From: | Joe Conway <mail(at)joeconway(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-10 17:41:46 |
Message-ID: | 411908DA.6090305@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Traci Sumpter | 2004-08-11 01:22:00 | LIKE '%%' does not return NULL |
Previous Message | Bruce Momjian | 2004-08-10 14:57:57 | Re: sleep function |