From d5ef2e2676da1cf3a45a795a5a1d2f72efc39096 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Mon, 25 Feb 2019 17:16:31 -0600 Subject: [PATCH] Add support for a left join lateral --- gems/ruby-qx/lib/qx.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gems/ruby-qx/lib/qx.rb b/gems/ruby-qx/lib/qx.rb index b612563a..1db46b59 100644 --- a/gems/ruby-qx/lib/qx.rb +++ b/gems/ruby-qx/lib/qx.rb @@ -40,6 +40,8 @@ class Qx str += expr[:LEFT_JOIN].map { |from, cond| " LEFT JOIN #{from} ON #{cond}" }.join if expr[:LEFT_JOIN] str += expr[:LEFT_OUTER_JOIN].map { |from, cond| " LEFT OUTER JOIN #{from} ON #{cond}" }.join if expr[:LEFT_OUTER_JOIN] str += expr[:JOIN_LATERAL].map {|i| " JOIN LATERAL (#{i[:select_statement]}) #{i[:join_name]} ON #{i[:success_condition]}"}.join if expr[:JOIN_LATERAL] + + str += expr[:LEFT_JOIN_LATERAL].map {|i| " LEFT JOIN LATERAL (#{i[:select_statement]}) #{i[:join_name]} ON #{i[:success_condition]}"}.join if expr[:LEFT_JOIN_LATERAL] str += ' WHERE ' + expr[:WHERE].map { |w| "(#{w})" }.join(' AND ') if expr[:WHERE] str += ' GROUP BY ' + expr[:GROUP_BY].join(', ') if expr[:GROUP_BY] str += ' HAVING ' + expr[:HAVING].map { |h| "(#{h})" }.join(' AND ') if expr[:HAVING] @@ -315,6 +317,14 @@ class Qx self end + + def left_join_lateral(join_name, select_statement, success_condition=true) + + @tree[:LEFT_JOIN_LATERAL] ||= [] + @tree[:LEFT_JOIN_LATERAL].concat([{join_name: join_name, select_statement: select_statement, success_condition: success_condition}]) + self + end + # - INSERT INTO / UPDATE # Allows three formats: