diff --git a/lib/pg_query/deparse.rb b/lib/pg_query/deparse.rb index e0214e9d..e3670711 100644 --- a/lib/pg_query/deparse.rb +++ b/lib/pg_query/deparse.rb @@ -413,11 +413,17 @@ def deparse_funccall(node) # COUNT(*) args << '*' if node['agg_star'] - name = (node['funcname'].map { |n| deparse_item(n, FUNC_CALL) } - ['pg_catalog']).join('.') - distinct = node['agg_distinct'] ? 'DISTINCT ' : '' - output << format('%s(%s%s)', name, distinct, args.join(', ')) - output << format('FILTER (WHERE %s)', deparse_item(node['agg_filter'])) if node['agg_filter'] - output << format('OVER %s', deparse_item(node['over'])) if node['over'] + name = (node['funcname'].map { |n| deparse_item(n, FUNC_CALL) }).join('.') + if name == 'pg_catalog.overlay' + # Note that this is a bit odd, but "OVERLAY" is a keyword on its own merit, and only accepts the + # keyword parameter style when its called as a keyword, not as a regular function (i.e. pg_catalog.overlay) + output << format('OVERLAY(%s PLACING %s FROM %s FOR %s)', args[0], args[1], args[2], args[3]) + else + distinct = node['agg_distinct'] ? 'DISTINCT ' : '' + output << format('%s(%s%s)', name, distinct, args.join(', ')) + output << format('FILTER (WHERE %s)', deparse_item(node['agg_filter'])) if node['agg_filter'] + output << format('OVER %s', deparse_item(node['over'])) if node['over'] + end output.join(' ') end diff --git a/spec/lib/pg_query/deparse_spec.rb b/spec/lib/pg_query/deparse_spec.rb index 92e6248e..3e6fad5f 100644 --- a/spec/lib/pg_query/deparse_spec.rb +++ b/spec/lib/pg_query/deparse_spec.rb @@ -169,6 +169,12 @@ it { is_expected.to eq oneline_query } end + context 'OVERLAY' do + let(:query) { 'SELECT OVERLAY("m"."name" PLACING \'******\' FROM 3 FOR 6) AS tc_kimlik FROM "tb_test" m' } + + it { is_expected.to eq query } + end + context 'SUM' do let(:query) { 'SELECT sum("price_cents") FROM "products"' }