Skip to content

Insert Keywords

This page lists the SQL keywords and clauses used in INSERT statements, along with their corresponding methods in ts-sql-query. It covers single and multi-row inserts, inserts from SELECT, default values, conflict resolution strategies (like ON CONFLICT or ON DUPLICATE KEY), and returning inserted rows.

SQL Keyword ts-sql-query Equivalent Notes Link
EXCLUDED table .valuesForInsert() Refers to the value that was attempted to be inserted during an upsert conflict. Insert on conflict do update ("upsert"), Insert API
INSERT INTO connection .insertInto(...) Inserts values in the database. Insert, Insert API
INSERT INTO ... VALUES (...) query .set(...) Inserts a single row with specified values. Insert multiple values, Insert API
INSERT INTO ... VALUES (...) query .values([...]) Inserts multiple rows in a single statement. Insert multiple values, Insert API
INSERT INTO ... SELECT query .from(...) Inserts rows resulting from a SELECT query. Insert from select, Insert API
INSERT INTO ... DEFAULT VALUES query .defaultValues() Inserts a row using default values for all columns. Insert API
INSERTED table .valuesForInsert() Refers to the value that was attempted to be inserted during an upsert conflict. Insert on conflict do update ("upsert"), Insert API
ON CONFLICT query .onConflictOn(...columns) Specifies the columns involved in the conflict resolution clause. Insert API
ON CONFLICT DO NOTHING query .onConflictDoNothing() Skips insertion if a conflict occurs on a unique or primary key. Insert on conflict do nothing, Insert API
ON CONFLICT DO UPDATE SET query .onConflictDoUpdateSet({...}) Updates existing row if a conflict occurs during insert. Insert on conflict do update ("upsert"), Insert API
ON CONFLICT ON CONSTRAINT query .onConflictOnConstraint('constraint_name') Refers to a specific constraint name instead of listing columns. Insert API
ON DUPLICATE KEY UPDATE query .onConflictDoUpdateSet({...}) MySQL-style upsert: updates row on duplicate key. Insert on conflict do update ("upsert"), Insert API
OUTPUT query .returning(...) Returns inserted values using SQL Server's OUTPUT clause. Insert returning, Insert API
RETURNING query .returning(...) Returns inserted rows or values after the operation. Insert returning, Insert API
RETURNING INTO query .returning(...) Returns inserted values into variables; Oracle-specific. Insert returning, Insert API
WHERE (on conflict) query .where(...) Restricts which conflicts will trigger the upsert logic. Insert API
WHERE (do update set) query .where(...) Filters which rows should be updated when a conflict occurs. Insert API
WITH query .forUseInQueryAs(...) Common Table Expression (CTE). Using a select as a view in another select query, Does ts-sql-query support common table expressions (CTE)?, Select API
WITH RECURSIVE query .forUseInQueryAs(...) Common Table Expression (CTE). Using a select as a view in another select query, Does ts-sql-query support common table expressions (CTE)?, Select API