Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/bulk_data_methods/monkey_patch_postgres.rb
Instance Method Summary collapse
-
#next_sequence_value(sequence_name) ⇒ Integer
Get the next value in a sequence.
-
#next_sequence_values(sequence_name, batch_size) ⇒ Array<Integer>
Get the some next values in a sequence.
Instance Method Details
#next_sequence_value(sequence_name) ⇒ Integer
Get the next value in a sequence. Used on INSERT operation for partitioning like by_id because the ID is required before the insert so that the specific child table is known ahead of time.
15 16 17 |
# File 'lib/bulk_data_methods/monkey_patch_postgres.rb', line 15 def next_sequence_value(sequence_name) return execute("select nextval('#{sequence_name}')").field_values("nextval").first.to_i end |
#next_sequence_values(sequence_name, batch_size) ⇒ Array<Integer>
Get the some next values in a sequence.
25 26 27 28 |
# File 'lib/bulk_data_methods/monkey_patch_postgres.rb', line 25 def next_sequence_values(sequence_name, batch_size) result = execute("select nextval('#{sequence_name}') from generate_series(1, #{batch_size})") return result.field_values("nextval").map(&:to_i) end |