Skip to content

Commit dc37712

Browse files
committed
params order
1 parent 1ed27ef commit dc37712

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

internal/compiler/analyze.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@ func (c *Compiler) _analyzeQuery(raw *ast.RawStmt, query string, failfast bool)
142142
raw, namedParams, edits := rewrite.NamedParameters(c.conf.Engine, raw, numbers, dollar)
143143

144144
var table *ast.TableName
145-
if n, ok := raw.Stmt.(*ast.InsertStmt); ok {
145+
switch n := raw.Stmt.(type) {
146+
case *ast.InsertStmt:
146147
var err error
147148
table, err = ParseTableName(n.Relation)
148149
if err := check(err); err != nil {
149150
return nil, err
150151
}
152+
if err := check(validate.InsertStmt(c.catalog, table, n)); err != nil {
153+
return nil, err
154+
}
151155
}
152156

153157
if err := check(validate.FuncCall(c.catalog, c.combo, raw)); err != nil {
@@ -181,11 +185,6 @@ func (c *Compiler) _analyzeQuery(raw *ast.RawStmt, query string, failfast bool)
181185
if err := check(err); err != nil {
182186
return nil, err
183187
}
184-
if n, ok := raw.Stmt.(*ast.InsertStmt); ok {
185-
if err := check(validate.InsertStmt(n, table, c.catalog)); err != nil {
186-
return nil, err
187-
}
188-
}
189188
cols, err := c.outputColumns(qc, raw.Stmt)
190189
if err := check(err); err != nil {
191190
return nil, err

internal/sql/validate/insert_stmt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
99
)
1010

11-
func InsertStmt(stmt *ast.InsertStmt, fqn *ast.TableName, c *catalog.Catalog) error {
11+
func InsertStmt(c *catalog.Catalog, fqn *ast.TableName, stmt *ast.InsertStmt) error {
1212
sel, ok := stmt.SelectStmt.(*ast.SelectStmt)
1313
if !ok {
1414
return nil
@@ -38,15 +38,15 @@ func InsertStmt(stmt *ast.InsertStmt, fqn *ast.TableName, c *catalog.Catalog) er
3838
Message: "INSERT has more expressions than target columns",
3939
}
4040
}
41-
return onConflictClause(stmt, fqn, c)
41+
return onConflictClause(c, fqn, stmt)
4242
}
4343

4444
// onConflictClause validates an ON CONFLICT DO UPDATE clause against the target
4545
// table. It checks:
4646
// - ON CONFLICT (col, ...) conflict target columns exist
4747
// - DO UPDATE SET col = ... assignment target columns exist
4848
// - EXCLUDED.col references exist
49-
func onConflictClause(n *ast.InsertStmt, fqn *ast.TableName, c *catalog.Catalog) error {
49+
func onConflictClause(c *catalog.Catalog, fqn *ast.TableName, n *ast.InsertStmt) error {
5050
if n.OnConflictClause == nil || n.OnConflictClause.Action != ast.OnConflictActionUpdate {
5151
return nil
5252
}

0 commit comments

Comments
 (0)