partitioned 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
|
-
|
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
|
#
|
data/lib/partitioned/version.rb
CHANGED