instance method
insert_sql
Ruby on Rails 4.2.9
Since v4.2.9 Last seen in v4.2.9Signature
insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
Executes an INSERT query and returns the new record’s ID
Parameters
-
sqlreq -
nameopt = nil -
pkopt = nil -
id_valueopt = nil -
sequence_nameopt = nil
Source
# File activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb, line 76
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
unless pk
# Extract the table from the insert sql. Yuck.
table_ref = extract_table_ref_from_insert_sql(sql)
pk = primary_key(table_ref) if table_ref
end
if pk && use_insert_returning?
select_value("#{sql} RETURNING #{quote_column_name(pk)}")
elsif pk
super
last_insert_id_value(sequence_name || default_sequence_name(table_ref, pk))
else
super
end
end
Defined in activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb line 76
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements