Skip to content

Commit

Permalink
Fix create_table :as on DB2
Browse files Browse the repository at this point in the history
DB2 doesn't appear to support WITH DATA, so handle it like derby
by doing it without data and then doing an insert.
  • Loading branch information
jeremyevans committed Apr 6, 2012
1 parent 90cfefd commit a5d3656
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/sequel/adapters/shared/db2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ def column_list_sql(g)
super
end

# Insert data from the current table into the new table after
# creating the table, since it is not possible to do it in one step.
def create_table_as(name, sql, options)
super
from(name).insert(sql.is_a?(Dataset) ? sql : dataset.with_sql(sql))
end

# DB2 requires parens around the SELECT, and DEFINITION ONLY at the end.
def create_table_as_sql(name, sql, options)
"#{create_table_prefix_sql(name, options)} AS (#{sql}) DEFINITION ONLY"
end

# Here we use DGTT which has most backward compatibility, which uses
# DECLARE instead of CREATE. CGTT can only be used after version 9.7.
# http://www.ibm.com/developerworks/data/library/techarticle/dm-0912globaltemptable/
Expand Down

0 comments on commit a5d3656

Please sign in to comment.