Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,8 @@ type Insert struct {
With *With
Partitions Partitions
Columns Columns
// Returning is specific to PostgreSQL syntax, and allows Insert statements to return
// results via a set of select expressions that are evaluated on the inserted rows.
// Returning is specific to PostgreSQL and MariaDB syntax, and allows Insert statements
//to return results via a set of select expressions that are evaluated on the inserted rows.
Returning SelectExprs
Rows InsertRows
OnDup OnDup
Expand All @@ -1713,6 +1713,9 @@ func (node *Insert) Format(buf *TrackedBuffer) {
buf.Myprintf(" partition (%v)", node.Partitions)
}
buf.Myprintf("%v %v%v", node.Columns, node.Rows, node.OnDup)
if len(node.Returning) > 0 {
buf.Myprintf(" returning %v", node.Returning)
}
}

// GetAuthInformation implements the AuthNode interface.
Expand Down Expand Up @@ -8141,15 +8144,15 @@ type Injectable interface {
// MySQL's dialect.
type InjectedExpr struct {
// Expression is an expression that implements the Expr interface. It can be any expression type.
Expression Injectable
Expression Injectable
// Children are the children of the expression, which can be any Expr type. This is a union type, and either this
// or SelectExprChildren will be set.
Children Exprs
// SelectExprChildren are the children of the expression, which can be any SelectExpr type. This is a union type,
Children Exprs
// SelectExprChildren are the children of the expression, which can be any SelectExpr type. This is a union type,
// and either this or Children will be set.
SelectExprChildren SelectExprs
// Auth contains the authentication information for the expression.
Auth AuthInformation
Auth AuthInformation
}

var _ Expr = InjectedExpr{}
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ var keywords = map[string]int{
"resource_group_user": RESOURCE_GROUP_USER,
"restrict": RESTRICT,
"return": RETURN,
"returning": RETURNING,
"reuse": REUSE,
"revoke": REVOKE,
"right": RIGHT,
Expand Down
33 changes: 22 additions & 11 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,22 @@ var (
{
input: "set @@session.validate_password.length = 1",
},
{
input: "insert into t1 values(1) returning pk",
output: "insert into t1 values (1) returning pk",
},
{
input: "insert into t2 (id) values (2),(3) returning id,t",
output: "insert into t2(id) values (2), (3) returning id, t",
},
{
input: "insert into t2(id,animal) values (1,'Dog'),(2,'Lion'),(3,'Tiger') returning id,id+id,id&id,id||id",
output: "insert into t2(id, animal) values (1, 'Dog'), (2, 'Lion'), (3, 'Tiger') returning id, id + id, id & id, id or id",
},
{
input: "insert into t1 set id1=1, animal1='Bear' returning f(id1), upper(animal1)",
output: "insert into t1(id1, animal1) values (1, 'Bear') returning f(id1), upper(animal1)",
},
}

// Any tests that contain multiple statements within the body (such as BEGIN/END blocks) should go here.
Expand Down Expand Up @@ -4945,8 +4961,8 @@ func TestSingleSQL(t *testing.T) {
t.Skip()
tests := []parseTest{
{
input: "select @`user var`",
output: "select @`user var`",
input: "insert into t1 values(1) returning pk",
output: "insert into t1 values (1) returning pk",
},
}
for _, tcase := range tests {
Expand Down Expand Up @@ -4975,15 +4991,6 @@ func TestAnsiQuotesMode(t *testing.T) {
}
}

func TestSingle(t *testing.T) {
validSQL = append(validSQL, validMultiStatementSql...)
for _, tcase := range validSQL {
if tcase.input == "select /* use */ 1 from t1 for system_time as of '2019-01-01'" {
runParseTestCase(t, tcase)
}
}
}

func TestGeneratedColumns(t *testing.T) {
tests := []parseTest{
{
Expand Down Expand Up @@ -5792,6 +5799,10 @@ func TestInvalid(t *testing.T) {
input: "select date concat('2001-', '02-', '03')",
err: "syntax error",
},
{
input: "insert into t (a) values (1) returning",
err: "syntax error",
},
}

for _, tcase := range invalidSQL {
Expand Down
Loading