instance method insert_sql

Ruby on Rails 4.2.9

Since v4.2.9 Last seen in v4.2.9

Signature

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

sql req
name opt = nil
pk opt = nil
id_value opt = nil
sequence_name opt = 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

Type at least 2 characters to search.

↑↓ navigate · open · esc close