module ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements
Public Instance Methods
execute(sql, name = nil)
click to toggle source
Executes an SQL statement, returning a PG::Result object on success or raising a PG::Error exception otherwise. Note: the PG::Result object is manually memory managed; if you don’t need it specifically, you may want consider the exec_query
wrapper.
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 39 def execute(sql, name = nil) sql = transform_query(sql) check_if_write_query(sql) materialize_transactions mark_transaction_written_if_write(sql) log(sql, name) do ActiveSupport::Dependencies.interlock.permit_concurrent_loads do @connection.async_exec(sql) end end end
explain(arel, binds = [])
click to toggle source
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 7 def explain(arel, binds = []) sql = "EXPLAIN #{to_sql(arel, binds)}" PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN", binds)) end
high_precision_current_timestamp()
click to toggle source
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 128 def high_precision_current_timestamp HIGH_PRECISION_CURRENT_TIMESTAMP end
Private Instance Methods
build_truncate_statements(table_names)
click to toggle source
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 137 def build_truncate_statements(table_names) ["TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}"] end
execute_batch(statements, name = nil)
click to toggle source
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 133 def execute_batch(statements, name = nil) execute(combine_multi_statements(statements)) end
last_insert_id_result(sequence_name)
click to toggle source
Returns the current ID of a table’s sequence.
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 142 def last_insert_id_result(sequence_name) exec_query("SELECT currval(#{quote(sequence_name)})", "SQL") end
suppress_composite_primary_key(pk)
click to toggle source
# File lib/active_record/connection_adapters/postgresql/database_statements.rb, line 146 def suppress_composite_primary_key(pk) pk unless pk.is_a?(Array) end