Skip to content

Commit

Permalink
Fix deparsing for Array functions (#163)
Browse files Browse the repository at this point in the history
Example: SELECT ARRAY(SELECT "id" FROM "products")::bigint[]
  • Loading branch information
emin100 authored Dec 27, 2020
1 parent c8f74aa commit 6989cda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pg_query/deparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ def deparse_sublink(node)
format('%s %s ALL (%s)', deparse_item(node['testexpr']), deparse_item(node['operName'][0], :operator), deparse_item(node['subselect']))
elsif node['subLinkType'] == SUBLINK_TYPE_EXISTS
format('EXISTS(%s)', deparse_item(node['subselect']))
elsif node['subLinkType'] == SUBLINK_TYPE_ARRAY
format('ARRAY(%s)', deparse_item(node['subselect']))
else
format('(%s)', deparse_item(node['subselect']))
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 @@ -175,6 +175,12 @@
it { is_expected.to eq query }
end

context 'ARRAY' do
let(:query) { 'SELECT ARRAY(SELECT "id" FROM "products")::bigint[]' }

it { is_expected.to eq query }
end

context 'LATERAL' do
let(:query) { 'SELECT "m"."name" AS mname, "pname" FROM "manufacturers" m, LATERAL get_product_names("m"."id") pname' }

Expand Down

0 comments on commit 6989cda

Please sign in to comment.