Methods
Instance Public methods
build_explain_clause(options = []) Link
execute(sql, name = nil, allow_retry: false) Link
Executes an SQL statement, returning a PG::Result object on success or raising a PG::Error exception otherwise.
Setting allow_retry
to true causes the db to reconnect and retry executing the SQL statement in case of a connection-related exception. This option should only be enabled for known idempotent queries.
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 activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb, line 44 def execute(sql, name = nil, allow_retry: false) sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) with_raw_connection(allow_retry: allow_retry) do |conn| log(sql, name) do result = conn.async_exec(sql) handle_warnings(sql) result end end ensure @notice_receiver_sql_warnings = [] end
explain(arel, binds = [], options = []) Link
# File activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb, line 7 def explain(arel, binds = [], options = []) sql = build_explain_clause(options) + " " + to_sql(arel, binds) result = exec_query(sql, "EXPLAIN", binds) PostgreSQL::ExplainPrettyPrinter.new.pp(result) end
high_precision_current_timestamp() Link
internal_execute(sql, name = "SCHEMA", allow_retry: true, uses_transaction: false) Link
# File activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb, line 61 def internal_execute(sql, name = "SCHEMA", allow_retry: true, uses_transaction: false) sql = transform_query(sql) check_if_write_query(sql) with_raw_connection(allow_retry: allow_retry, uses_transaction: uses_transaction) do |conn| log(sql, name) do conn.async_exec(sql) end end end