@@ -41,16 +41,21 @@ func InsertStmt(c *catalog.Catalog, fqn *ast.TableName, stmt *ast.InsertStmt) er
4141 }
4242 }
4343
44- return onConflictClause (c , fqn , stmt )
44+ for _ , clause := range stmt .OnConflictClauses {
45+ if err := onConflictClause (c , fqn , clause ); err != nil {
46+ return err
47+ }
48+ }
49+ return nil
4550}
4651
4752// onConflictClause validates an ON CONFLICT DO UPDATE clause against the target
4853// table. It checks:
4954// - ON CONFLICT (col, ...) conflict target columns exist
5055// - DO UPDATE SET col = ... assignment target columns exist
5156// - EXCLUDED.col references exist
52- func onConflictClause (c * catalog.Catalog , fqn * ast.TableName , n * ast.InsertStmt ) error {
53- if fqn == nil || n . OnConflictClause == nil || n . OnConflictClause .Action != ast .OnConflictActionUpdate {
57+ func onConflictClause (c * catalog.Catalog , fqn * ast.TableName , n * ast.OnConflictClause ) error {
58+ if fqn == nil || n == nil || n .Action != ast .OnConflictActionUpdate {
5459 return nil
5560 }
5661
@@ -66,35 +71,35 @@ func onConflictClause(c *catalog.Catalog, fqn *ast.TableName, n *ast.InsertStmt)
6671 }
6772
6873 // DO UPDATE requires a conflict target: ON CONFLICT (col) or ON CONFLICT ON CONSTRAINT name.
69- if n .OnConflictClause . Infer == nil {
74+ if n .Infer == nil {
7075 return & sqlerr.Error {
7176 Code : "42601" ,
7277 Message : "ON CONFLICT DO UPDATE requires inference specification or constraint name" ,
7378 }
7479 }
7580
7681 // Validate ON CONFLICT (col, ...) conflict target columns.
77- if n .OnConflictClause . Infer .IndexElems != nil {
78- for _ , item := range n .OnConflictClause . Infer .IndexElems .Items {
82+ if n .Infer .IndexElems != nil {
83+ for _ , item := range n .Infer .IndexElems .Items {
7984 elem , ok := item .(* ast.IndexElem )
8085 if ! ok || elem .Name == nil {
8186 continue
8287 }
8388
8489 if _ , exists := colNames [* elem .Name ]; ! exists {
8590 e := sqlerr .ColumnNotFound (table .Rel .Name , * elem .Name )
86- e .Location = n .OnConflictClause . Infer .Location
91+ e .Location = n .Infer .Location
8792 return e
8893 }
8994 }
9095 }
9196
9297 // Validate DO UPDATE SET col = ... assignment target columns and EXCLUDED.col references.
93- if n .OnConflictClause . TargetList == nil {
98+ if n .TargetList == nil {
9499 return nil
95100 }
96101
97- for _ , item := range n .OnConflictClause . TargetList .Items {
102+ for _ , item := range n .TargetList .Items {
98103 target , ok := item .(* ast.ResTarget )
99104 if ! ok || target .Name == nil {
100105 continue
0 commit comments