Skip to content

Commit

Permalink
Empty target list support (pganalyze#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
emin100 authored and lfittl committed Nov 11, 2019
1 parent 1929594 commit 467c762
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/pg_query/deparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,9 @@ def deparse_select(node) # rubocop:disable Metrics/CyclomaticComplexity
output.join(' ')
end

output << 'SELECT' if node[FROM_CLAUSE_FIELD] || node[TARGET_LIST_FIELD]

if node[TARGET_LIST_FIELD]
output << 'SELECT'
if node['distinctClause']
output << 'DISTINCT'
unless node['distinctClause'].compact.empty?
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/pg_query/deparse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
it { is_expected.to eq query }
end

context 'with empty target list' do
let(:query) { 'SELECT FROM "x" WHERE "y" = 5 AND "z" = "y"' }

it { is_expected.to eq query }
end

context 'basic statement with schema' do
let(:query) { 'SELECT "a" AS b FROM "public"."x" WHERE "y" = 5 AND "z" = "y"' }

Expand Down

0 comments on commit 467c762

Please sign in to comment.