diff --git a/lib/pg_query/deparse.rb b/lib/pg_query/deparse.rb index 75afe5ff..51b12d29 100644 --- a/lib/pg_query/deparse.rb +++ b/lib/pg_query/deparse.rb @@ -90,6 +90,10 @@ def deparse_item(item, context = nil) # rubocop:disable Metrics/CyclomaticComple deparse_create_function(node) when CREATE_STMT deparse_create_table(node) + when CREATE_TABLE_AS_STMT + deparse_create_table_as(node) + when INTO_CLAUSE + deparse_into_clause(node) when DEF_ELEM deparse_defelem(node) when DELETE_STMT @@ -669,6 +673,19 @@ def deparse_create_table(node) output.join(' ') end + def deparse_create_table_as(node) + output = [] + output << 'CREATE TEMPORARY TABLE' + output << deparse_item(node['into']) + output << 'AS' + output << deparse_item(node['query']) + output.join(' ') + end + + def deparse_into_clause(node) + deparse_item(node['rel']) + end + def deparse_when(node) output = ['WHEN'] output << deparse_item(node['expr']) diff --git a/spec/lib/pg_query/deparse_spec.rb b/spec/lib/pg_query/deparse_spec.rb index 73a48aab..d15f32b8 100644 --- a/spec/lib/pg_query/deparse_spec.rb +++ b/spec/lib/pg_query/deparse_spec.rb @@ -793,6 +793,12 @@ it { is_expected.to eq oneline_query } end + + context 'temporary table' do + let(:query) { 'CREATE TEMPORARY TABLE "temp" AS SELECT "c" FROM "t"' } + + it { is_expected.to eq oneline_query } + end end context 'DROP TABLE' do