lib/pgslice.rb in pgslice-0.3.0 vs lib/pgslice.rb in pgslice-0.3.1
- old
+ new
@@ -50,11 +50,10 @@
# commands
def prep
table, column, period = arguments
- cast = column_cast(table, column)
intermediate_table = "#{table}_intermediate"
trigger_name = self.trigger_name(table)
if options[:no_partition]
abort "Usage: pgslice prep <table> --no-partition" if arguments.length != 1
@@ -90,10 +89,11 @@
CREATE TRIGGER #{trigger_name}
BEFORE INSERT ON #{intermediate_table}
FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}();
SQL
+ cast = column_cast(table, column)
queries << <<-SQL
COMMENT ON TRIGGER #{trigger_name} ON #{intermediate_table} is 'column:#{column},period:#{period},cast:#{cast}';
SQL
end
@@ -260,11 +260,10 @@
end
starting_id = max_dest_id
fields = columns(source_table).map { |c| PG::Connection.quote_ident(c) }.join(", ")
batch_size = options[:batch_size]
- cast = column_cast(table, field)
i = 1
batch_count = ((max_source_id - starting_id) / batch_size.to_f).ceil
while starting_id < max_source_id
where = "#{primary_key} > #{starting_id} AND #{primary_key} <= #{starting_id + batch_size}"
@@ -483,10 +482,9 @@
query << " WHERE #{conditions.join(" AND ")}" if conditions.any?
execute(query)[0]["max"].to_i
end
def min_id(table, primary_key, column, cast, starting_time, where)
- cast = column_cast(table, column)
query = "SELECT MIN(#{primary_key}) FROM #{table}"
conditions = []
conditions << "#{column} >= #{sql_date(starting_time, cast)}" if starting_time
conditions << where if where
query << " WHERE #{conditions.join(" AND ")}" if conditions.any?