{"record":{"id":"8cfc911349b199d8","repo":"ent/ent","slug":"sql-select-for-update-share-not-supported-in-s","errorCode":null,"errorMessage":"sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite","messagePattern":"sql: SELECT \\.\\. FOR UPDATE/SHARE not supported in SQLite","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dialect/sql/builder.go","lineNumber":2451,"sourceCode":"// WithLockClause allows providing a custom clause for\n// locking the statement. For example, in MySQL <= 8.22:\n//\n//\tSelect().\n//\tFrom(Table(\"users\")).\n//\tForShare(\n//\t\tWithLockClause(\"LOCK IN SHARE MODE\"),\n//\t)\nfunc WithLockClause(clause string) LockOption {\n\treturn func(c *LockOptions) {\n\t\tc.clause = clause\n\t}\n}\n\n// For sets the lock configuration for suffixing the `SELECT`\n// statement with the `FOR [SHARE | UPDATE] ...` clause.\nfunc (s *Selector) For(l LockStrength, opts ...LockOption) *Selector {\n\tif s.Dialect() == dialect.SQLite {\n\t\ts.AddError(errors.New(\"sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite\"))\n\t}\n\ts.lock = &LockOptions{Strength: l}\n\tfor _, opt := range opts {\n\t\topt(s.lock)\n\t}\n\treturn s\n}\n\n// ForShare sets the lock configuration for suffixing the\n// `SELECT` statement with the `FOR SHARE` clause.\nfunc (s *Selector) ForShare(opts ...LockOption) *Selector {\n\treturn s.For(LockShare, opts...)\n}\n\n// ForUpdate sets the lock configuration for suffixing the\n// `SELECT` statement with the `FOR UPDATE` clause.\nfunc (s *Selector) ForUpdate(opts ...LockOption) *Selector {\n\treturn s.For(LockUpdate, opts...)","sourceCodeStart":2433,"sourceCodeEnd":2469,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/dialect/sql/builder.go#L2433-L2469","documentation":"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.","triggerScenarios":"Thrown at dialect/sql/builder.go:2451 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["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.","Collect the error via the selector's Err()/QueryErr before running the statement so the unsupported path fails fast."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}