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