Re: function expression in FROM may not refer to other relations
От | Joe Conway |
---|---|
Тема | Re: function expression in FROM may not refer to other relations |
Дата | |
Msg-id | 411908DA.6090305@joeconway.com обсуждение исходный текст |
Ответ на | function expression in FROM may not refer to other relations of same query level ("Philippe Lang" <philippe.lang@attiksystem.ch>) |
Список | 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
В списке pgsql-sql по дате отправления: