ent/ent · error

sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite

Error message

sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite

What it means

Capability check in Selector.For: SQLite does not support row-locking suffixes (SELECT ... FOR UPDATE / FOR SHARE), so when the selector's dialect is SQLite the call records this error instead of writing the lock clause. The offending input is the combination of a SQLite dialect with a For/LockStrength call.

Source

Thrown at dialect/sql/builder.go:2451

// WithLockClause allows providing a custom clause for
// locking the statement. For example, in MySQL <= 8.22:
//
//	Select().
//	From(Table("users")).
//	ForShare(
//		WithLockClause("LOCK IN SHARE MODE"),
//	)
func WithLockClause(clause string) LockOption {
	return func(c *LockOptions) {
		c.clause = clause
	}
}

// For sets the lock configuration for suffixing the `SELECT`
// statement with the `FOR [SHARE | UPDATE] ...` clause.
func (s *Selector) For(l LockStrength, opts ...LockOption) *Selector {
	if s.Dialect() == dialect.SQLite {
		s.AddError(errors.New("sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite"))
	}
	s.lock = &LockOptions{Strength: l}
	for _, opt := range opts {
		opt(s.lock)
	}
	return s
}

// ForShare sets the lock configuration for suffixing the
// `SELECT` statement with the `FOR SHARE` clause.
func (s *Selector) ForShare(opts ...LockOption) *Selector {
	return s.For(LockShare, opts...)
}

// ForUpdate sets the lock configuration for suffixing the
// `SELECT` statement with the `FOR UPDATE` clause.
func (s *Selector) ForUpdate(opts ...LockOption) *Selector {
	return s.For(LockUpdate, opts...)

View on GitHub (pinned to 69d5d4deb1)

Solutions

  1. Only apply For(Update/Share) on dialects that support it (PostgreSQL, MySQL); skip locking for SQLite since it locks the whole database file on write anyway.
  2. Collect the error via the selector's Err()/QueryErr before running the statement so the unsupported path fails fast.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at dialect/sql/builder.go:2451 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ent/ent@69d5d4deb1 (2026-09-03). Data as JSON: /api/errors/8cfc911349b199d8. Report an issue: GitHub.