Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create table as stmt #102

Merged
merged 3 commits into from Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/pg_query/deparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])
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 @@ -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
Expand Down