Adds multiple records to the specified table. The operation is synchronous, meaning that a response will not be returned until all the records are fully inserted and available. The response payload provides the counts of the number of records actually inserted and/or updated, and can provide the unique identifier of each added record.
The input parameter options parameter can be used to customize this function’s behavior.
The update_on_existing_pk option specifies the record collision policy for inserting into a table with a primary key, but is ignored if no primary key exists.
The return_record_ids option indicates that the database should return the unique identifiers of inserted records.
Parameters
Name of table to which the records are to be added, in [schema_name.]table_name format, using standard name resolution rules. Must be an existing table.
An array of binary or json encoded data, or Record objects for the records to be added. The user can provide a single element (which will be automatically promoted to a list internally) or a list. The user can provide a single element (which will be automatically promoted to a list internally) or a list.
The encoding of the records to be inserted. Allowed values are:
binary
json
The default value is ‘binary’.
Optional parameters. Allowed keys are:
update_on_existing_pk – Specifies the record collision policy for inserting into a table with a primary key. If set to true, any existing table record with primary key values that match those of a record being inserted will be replaced by that new record (the new data will be “upserted”). If set to false, any existing table record with primary key values that match those of a record being inserted will remain unchanged, while the new record will be rejected and the error handled as determined by ignore_existing_pk, allow_partial_batch, and return_individual_errors. If the specified table does not have a primary key, then this option has no effect. Allowed values are:
true – Upsert new records when primary keys match existing records.
false – Reject new records when primary keys match existing records.
The default value is ‘false’.
enable_inplace_updates – Applies only when upserting (when update_on_existing_pk is true). If set to true, an existing record matched by primary key is modified in place. If set to false, it is updated by deleting the existing record and inserting a replacement (delete and insert), which prevents the change from being reflected in dependent materialized views until they are refreshed. Allowed values are:
true
false
The default value is ‘true’.
ignore_existing_pk – Specifies the record collision error-suppression policy for inserting into a table with a primary key, only used when not in upsert mode (upsert mode is disabled when update_on_existing_pk is false). If set to true, any record being inserted that is rejected for having primary key values that match those of an existing table record will be ignored with no error generated. If false, the rejection of any record for having primary key values matching an existing record will result in an error being reported, as determined by allow_partial_batch and return_individual_errors. If the specified table does not have a primary key or if upsert mode is in effect (update_on_existing_pk is true), then this option has no effect. Allowed values are:
true – Ignore new records whose primary key values collide with those of existing records.
false – Treat as errors any new records whose primary key values collide with those of existing records.
The default value is ‘false’.
pk_conflict_predicate_higher – The record with higher value for the column resolves the primary-key insert conflict. The default value is ‘’.
pk_conflict_predicate_lower – The record with lower value for the column resolves the primary-key insert conflict. The default value is ‘’.
return_record_ids – If true then return the internal record id along for each inserted record. Allowed values are:
true
false
The default value is ‘false’.
truncate_strings – If set to true, any strings which are too long for their target charN string columns will be truncated to fit. Allowed values are:
true
false
The default value is ‘false’.
return_individual_errors – If set to true, success will always be returned, and any errors found will be included in the info map. The “bad_record_indices” entry is a comma-separated list of bad records (0-based). If so, there will also be an “error_N” entry for each record with an error, where N is the index (0-based). Allowed values are:
true
false
The default value is ‘false’.
allow_partial_batch – If set to true, all correct records will be inserted and incorrect records will be rejected and reported. Otherwise, the entire batch will be rejected if any records are incorrect. Allowed values are:
true
false
The default value is ‘false’.
error_handling – Specifies how errors should be handled upon insertion. When set, this option is authoritative; supplying a contradictory allow_partial_batch is an error. Allowed values are:
permissive – Records with bad column values are kept when possible: the offending column is filled with its default value if one exists, otherwise with null if the column is nullable; if neither is possible the record is skipped and reported.
skip – Records with bad values are skipped and reported; the rest of the batch is inserted.
abort – Stops the insertion and rejects the remaining batch when any record is incorrect.
The default value is ‘abort’.
dry_run – If set to true, no data will be saved and any errors will be returned. Allowed values are:
true
false
The default value is ‘false’.
request_schema_str – Type schema of input parameter list (when input parameter list_encoding is binary), in [[“column_name”,”column_type”]] format. When non-empty and different from the table’s schema, the server remaps the incoming records to the table’s full schema. Columns present in the table but absent from this schema are filled using their default values, NULL (if nullable), or an error is returned. If empty, records must match the table’s full schema. The default value is ‘’.
transformations – Comma-separated expressions, one per target table column. Each expression is evaluated per record. Empty entries (two consecutive commas) mean no transformation for that column – the value is resolved from the input record, table default, NULL, or an error. Expressions may reference input columns by name or by position (2 for the second, etc.). The default value is ‘’.
The default value is an empty dict ( ).
A RecordType object using which the binary data will be encoded. If None, then it is assumed that the data is already encoded, and no further encoding will occur. Default is None.
Returns
A dict with the following entries–
An array containing the IDs with which the added records are identified internally.
The number of records inserted.
The number of records updated.
Additional information. Allowed keys are:
bad_record_indices – If return_individual_errors option is specified or implied, returns a comma-separated list of invalid indices (0-based).
error_N – Error message for record at index N (0-based).