Skip to content

Commit

Permalink
Deparse function call indirection (#116)
Browse files Browse the repository at this point in the history
* Unit test deparse function call indirection

* Deparse function call indirection
  • Loading branch information
herwinw authored and lfittl committed Jul 1, 2019
1 parent 7b6c902 commit 7f961cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/pg_query/deparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ def deparse_a_star(_node)
end

def deparse_a_indirection(node)
output = [deparse_item(node['arg'])]
output = []
arg = deparse_item(node['arg'])
output << if node['arg'].key?(FUNC_CALL)
"(#{arg})."
else
arg
end
node['indirection'].each do |subnode|
output << deparse_item(subnode)
end
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 @@ -298,6 +298,12 @@
it { is_expected.to eq query }
end

context 'query indirection' do
let(:query) { 'SELECT (foo(1))."y"' }

it { is_expected.to eq query }
end

context 'complex indirection' do
let(:query) { 'SELECT * FROM "x" WHERE "y" = "z"[?][?]' }

Expand Down

0 comments on commit 7f961cd

Please sign in to comment.