FOR UPDATE

constructsupportedQueries & DML

docs.snowflake.com ↗

Locks the rows that the query selects until the transaction that contains the query commits or aborts. This clause is supported for use with hybrid tables only, and is useful for transactional workloads in which multiple transactions attempt to access the same rows at the same time. Rows are locked for update in the sense that other transactions cannot write data to these rows until the transaction doing the locking has been fully committed or rolled back. However, other transactions can read the locked rows, and other rows in the same table can be read, updated, or deleted.

Parameters

NameRequiredDescription
NOWAITReturns an error if the transaction cannot lock the selected rows immediately. NOWAIT is the default.
WAIT wait_timeSpecifies the maximum time (in seconds) that the query waits to acquire row-level locks. If the wait time expires, the query returns an error.

Usage notes

Parameters

NOWAIT: Returns an error if the transaction cannot lock the selected rows immediately. NOWAIT is the default. WAIT wait_time: Specifies the maximum time (in seconds) that the query waits to acquire row-level locks. If the wait time expires, the query returns an error.

Restrictions

The FOR UPDATE clause: - Cannot be used with AUTOCOMMIT transactions. - Must be the last clause in the SELECT statement. - Cannot be used in a CTAS statement. - Cannot be used inside subqueries. - Cannot select from multiple tables (joins) or set operations. - Cannot be used when the query contains: DISTINCT - Aggregation functions - GROUP BY - HAVING - Sequences