Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions enginetest/queries/insert_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,26 @@ var InsertScripts = []ScriptTest{
},
},
},
{
Name: "insert...returning... statements",
SetUpScript: []string{
"CREATE TABLE animals (id int, name varchar(20))",
},
Assertions: []ScriptTestAssertion{
{
Query: "insert into animals (id) values (2) returning id",
Expected: []sql.Row{{2}},
},
{
Query: "insert into animals(id,name) values (1, 'Dog'),(2,'Lion'),(3,'Tiger'),(4,'Leopard') returning id, id+id",
Expected: []sql.Row{{1, 2}, {2, 4}, {3, 6}, {4, 8}},
},
{
Query: "insert into animals set id=1,name='Bear' returning id,name",
Expected: []sql.Row{{1, "Bear"}},
},
},
},
}

var InsertDuplicateKeyKeyless = []ScriptTest{
Expand Down
5 changes: 4 additions & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ func (h *Handler) ComPrepare(ctx context.Context, c *mysql.Conn, query string, p
// than they will at execution time.
func nodeReturnsOkResultSchema(node sql.Node) bool {
switch node.(type) {
case *plan.InsertInto, *plan.Update, *plan.UpdateJoin, *plan.DeleteFrom:
case *plan.InsertInto:
insertNode, _ := node.(*plan.InsertInto)
return insertNode.Returning == nil
case *plan.Update, *plan.UpdateJoin, *plan.DeleteFrom:
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion sql/plan/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type InsertInto struct {
LiteralValueSource bool

// Returning is a list of expressions to return after the insert operation. This feature is not supported
// in MySQL's syntax, but is exposed through PostgreSQL's syntax.
// in MySQL's syntax, but is exposed through PostgreSQL's and MariaDB's syntax.
Returning []sql.Expression

// FirstGenerateAutoIncRowIdx is the index of the first row inserted that increments last_insert_id.
Expand Down
Loading