Skip to Content Skip to Search
Methods
B
E
H
I

Instance Public methods

build_explain_clause(options = [])

# File activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb, line 156
def build_explain_clause(options = [])
  return "EXPLAIN" if options.empty?

  "EXPLAIN (#{options.join(", ").upcase})"
end

execute(sql, name = nil, allow_retry: false)

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 = [])

# 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()

# File activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb, line 152
def high_precision_current_timestamp
  HIGH_PRECISION_CURRENT_TIMESTAMP
end

internal_execute(sql, name = "SCHEMA", allow_retry: true, uses_transaction: false)

# 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