MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / InsertStmt

Function InsertStmt

internal/sql/validate/insert_stmt.go:13–45  ·  view source on GitHub ↗
(c *catalog.Catalog, fqn *ast.TableName, stmt *ast.InsertStmt)

Source from the content-addressed store, hash-verified

11const excludedTable = "EXCLUDED"
12
13func InsertStmt(c *catalog.Catalog, fqn *ast.TableName, stmt *ast.InsertStmt) error {
14 sel, ok := stmt.SelectStmt.(*ast.SelectStmt)
15 if !ok {
16 return nil
17 }
18 if sel.ValuesLists == nil {
19 return nil
20 }
21 if len(sel.ValuesLists.Items) != 1 {
22 return nil
23 }
24 sublist, ok := sel.ValuesLists.Items[0].(*ast.List)
25 if !ok {
26 return nil
27 }
28
29 colsLen := len(stmt.Cols.Items)
30 valsLen := len(sublist.Items)
31 switch {
32 case colsLen > valsLen:
33 return &sqlerr.Error{
34 Code: "42601",
35 Message: "INSERT has more target columns than expressions",
36 }
37 case colsLen < valsLen:
38 return &sqlerr.Error{
39 Code: "42601",
40 Message: "INSERT has more expressions than target columns",
41 }
42 }
43
44 return onConflictClause(c, fqn, stmt)
45}
46
47// onConflictClause validates an ON CONFLICT DO UPDATE clause against the target
48// table. It checks:

Callers 1

_analyzeQueryMethod · 0.92

Calls 1

onConflictClauseFunction · 0.85

Tested by

no test coverage detected