S-SQL and nested joins -- correct version
Hello, My apologies, I sent my previous email by mistake before I'd finished composing it. Here is the completed email: Is there an S-SQL expression which will produce nested join expressions like this one: select * from table_1 inner join table_2 inner join table_3 on table_2.c = table_3.d on table_1.a = test_2.b; (This form is described in section 7.2.1.1 of the Postgres documentation, which says, "Joins of all types can be chained together or nested: either or both T1 and T2 can be joined tables.") I know I can do this: (:select '* :from 'table-1 :inner-join 'table-2 :on (:= 'table-1.a 'table-2.b) :inner-join 'table-3 :on (:= 'table-2.c 'table-3.d)) which produces a chained join expression: (SELECT * FROM table_1 INNER JOIN table_2 ON (table_1.a = table_2.b) INNER JOIN table_3 ON (table_2.c = table_3.d)) However, these chained join expressions behave differently than nested ones when mixing different types of joins (inner with outer, etc.), and I need the behavior of the nested expression. I tried this: (:select '* :from 'table-1 :inner-join 'table-2 :inner-join 'table-3 :on (:= 'table-2.c 'table-3.d) :on (:= 'table-1.a 'table-2.b)) But it produces the error "Incorrect join form in select." Am I missing the correct syntax, or is this unsupported right now? Thank you, -Eli
Hi Eli, I don't believe this is supported right now. Take a look at the code that parses joins, if you want to be sure. Best, Marijn On Fri, Feb 28, 2014 at 2:13 AM, Eli Naeher <enaeher@gmail.com> wrote:
Hello,
My apologies, I sent my previous email by mistake before I'd finished composing it. Here is the completed email:
Is there an S-SQL expression which will produce nested join expressions like this one:
select * from table_1 inner join table_2 inner join table_3 on table_2.c = table_3.d on table_1.a = test_2.b;
(This form is described in section 7.2.1.1 of the Postgres documentation, which says, "Joins of all types can be chained together or nested: either or both T1 and T2 can be joined tables.")
I know I can do this:
(:select '* :from 'table-1 :inner-join 'table-2 :on (:= 'table-1.a 'table-2.b) :inner-join 'table-3 :on (:= 'table-2.c 'table-3.d))
which produces a chained join expression:
(SELECT * FROM table_1 INNER JOIN table_2 ON (table_1.a = table_2.b) INNER JOIN table_3 ON (table_2.c = table_3.d))
However, these chained join expressions behave differently than nested ones when mixing different types of joins (inner with outer, etc.), and I need the behavior of the nested expression. I tried this:
(:select '* :from 'table-1 :inner-join 'table-2 :inner-join 'table-3 :on (:= 'table-2.c 'table-3.d) :on (:= 'table-1.a 'table-2.b))
But it produces the error "Incorrect join form in select."
Am I missing the correct syntax, or is this unsupported right now?
Thank you, -Eli
participants (2)
-
Eli Naeher
-
Marijn Haverbeke