From 6989cda8e27b99ded053142e312aed24ba972fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20KARAKA=C5=9E?= Date: Mon, 28 Dec 2020 00:48:24 +0300 Subject: [PATCH] Fix deparsing for Array functions (#163) Example: SELECT ARRAY(SELECT "id" FROM "products")::bigint[] --- lib/pg_query/deparse.rb | 2 ++ spec/lib/pg_query/deparse_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/pg_query/deparse.rb b/lib/pg_query/deparse.rb index 4e30e647..52396f17 100644 --- a/lib/pg_query/deparse.rb +++ b/lib/pg_query/deparse.rb @@ -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 diff --git a/spec/lib/pg_query/deparse_spec.rb b/spec/lib/pg_query/deparse_spec.rb index 2dd27bc3..8a55c8bc 100644 --- a/spec/lib/pg_query/deparse_spec.rb +++ b/spec/lib/pg_query/deparse_spec.rb @@ -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' }