partitioned 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -116,7 +116,48 @@ module Partitioned
116
116
  # Create a single child table.
117
117
  #
118
118
  def create_partition_table(*partition_key_values)
119
- execute("select * into #{configurator.table_name(*partition_key_values)} from #{configurator.parent_table_name(*partition_key_values)} where false")
119
+ # XXX needs to set search path if parent table is not in search path
120
+ # show search_path
121
+ # set search_path to '$user', 'public', 'bids_partitions';
122
+
123
+ # select * from pg_table_def where tablename = 'bids' and schemaname = 'public';
124
+ ## column, type, encoding, distkey, sortkey, not null
125
+ sortkeys = []
126
+ sql_columns = []
127
+
128
+ sql = "select * from pg_table_def where tablename = '#{configurator.parent_table_name(*partition_key_values)}' and schemaname = '#{configurator.parent_table_schema_name(*partition_key_values)}'"
129
+ sql_column_rows = execute(sql)
130
+ sql_column_rows.each do |row|
131
+ column_info = []
132
+ column_name = row['column']
133
+ column_info << column_name
134
+ column_info << row['type']
135
+ if row['notnull'] == "t"
136
+ column_info << "not null"
137
+ end
138
+ if row['encoding'] != 'none'
139
+ column_info << "encode #{row['encoding']}"
140
+ end
141
+ if row['sortkey'] != "0"
142
+ sortkeys[row['sortkey'].to_i - 1] = column_name
143
+ end
144
+ sql_columns << column_info.join(" ")
145
+ end
146
+
147
+ if sortkeys.blank?
148
+ sql_sortkeys = ""
149
+ else
150
+ sql_sortkeys = " sortkey (#{sortkeys.join(',')})"
151
+ end
152
+ sql = <<-SQL
153
+ create table #{configurator.table_name(*partition_key_values)}
154
+ (
155
+ #{sql_columns.join(', ')}
156
+ ) #{sql_sortkeys}
157
+ SQL
158
+ execute(sql)
159
+
160
+ # unset search_path
120
161
  end
121
162
 
122
163
  #
@@ -1,4 +1,4 @@
1
1
  module Partitioned
2
2
  # the current version of this gem
3
- VERSION = "1.1.5"
3
+ VERSION = "1.1.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: partitioned
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: