From 68744177db1c909ee070146f202ea1ae05824606 Mon Sep 17 00:00:00 2001 From: Markus Ecker Date: Mon, 24 Aug 2015 23:04:53 +0200 Subject: [PATCH 1/2] support deparsing cross joins --- lib/pg_query/deparse.rb | 1 + spec/lib/pg_query/deparse_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/pg_query/deparse.rb b/lib/pg_query/deparse.rb index b7369d2d..6785742c 100644 --- a/lib/pg_query/deparse.rb +++ b/lib/pg_query/deparse.rb @@ -333,6 +333,7 @@ def deparse_joinexpr(node) output = [] output << deparse_item(node['larg']) output << 'LEFT' if node['jointype'] == 1 + output << 'CROSS' if node['jointype'] == 0 && node['quals'] == nil output << 'JOIN' output << deparse_item(node['rarg']) diff --git a/spec/lib/pg_query/deparse_spec.rb b/spec/lib/pg_query/deparse_spec.rb index d2a00218..b2e4eb80 100644 --- a/spec/lib/pg_query/deparse_spec.rb +++ b/spec/lib/pg_query/deparse_spec.rb @@ -70,6 +70,13 @@ it { is_expected.to eq oneline_query } end + context 'CROSS JOIN' do + let(:query) do + "SELECT x, y FROM a CROSS JOIN b" + end + it { is_expected.to eq query } + end + context 'omitted FROM clause' do let(:query) { 'SELECT 2 + 2' } it { is_expected.to eq query } From fd191a1d02d4d32ef30e1d38dbd40022ad66a14b Mon Sep 17 00:00:00 2001 From: Markus Ecker Date: Tue, 25 Aug 2015 23:36:15 +0200 Subject: [PATCH 2/2] Fix rubocop complaints --- lib/pg_query/deparse.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pg_query/deparse.rb b/lib/pg_query/deparse.rb index 6785742c..18757bc1 100644 --- a/lib/pg_query/deparse.rb +++ b/lib/pg_query/deparse.rb @@ -333,7 +333,7 @@ def deparse_joinexpr(node) output = [] output << deparse_item(node['larg']) output << 'LEFT' if node['jointype'] == 1 - output << 'CROSS' if node['jointype'] == 0 && node['quals'] == nil + output << 'CROSS' if node['jointype'] == 0 && node['quals'].nil? output << 'JOIN' output << deparse_item(node['rarg'])