(c *catalog.Catalog, fqn *ast.TableName, stmt *ast.InsertStmt)
| 11 | const excludedTable = "EXCLUDED" |
| 12 | |
| 13 | func 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: |
no test coverage detected