Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlparser errors on auto_increment not null but handles not null auto_increment #5685

Closed
jmhodges opened this issue Jan 10, 2020 · 2 comments

Comments

@jmhodges
Copy link
Contributor

The order of auto_increment not null vs not null auto_increment in create table statements doesn't matter to mysql, but sqlparser returns an error in the first case.

That is, this statement errors out when parsed:

create table blocked_domains (id bigint auto_increment not null, primary key (id));

while this one parses fine:

create table blocked_domains (id bigint not null auto_increment, primary key (id));

Sample code:

package main

import (
	"fmt"

	"github.com/vitessio/vitess/go/vt/sqlparser"
)

func main() {
	notNullLast := "create table blocked_domains (id bigint auto_increment not null, primary key (id));"
	if err := parse(notNullLast); err != nil {
		fmt.Printf("notNullLast errored: %s\n", err)
	} else {
		fmt.Println("notNullLast worked")
	}
	notNullFirst := "create table blocked_domains (id bigint not null auto_increment, primary key (id));"
	if err := parse(notNullFirst); err != nil {
		fmt.Printf("notNullFirst errored: %s\n", err)
	} else {
		fmt.Println("notNullFirst worked")
	}
}

func parse(contents string) error {
	t := sqlparser.NewStringTokenizer(contents)
	_, err := sqlparser.ParseNextStrictDDL(t)
	return err
}

That will produce

notNullLast errored: syntax error at position 59 near 'not'
notNullFirst worked

and we'd like to not see that first error.

@saifalharthi
Copy link
Contributor

This seems to be fixed, I tested it on master.
For the first ordering

mysql> create table blocked_domains (id bigint auto_increment not null, primary key (id));
Query OK, 0 rows affected (0.03 sec)

For the second ordering

mysql> create table blocked_domains (id bigint not null auto_increment, primary key (id));
Query OK, 0 rows affected (0.03 sec)

I think we can close this issue.

@systay
Copy link
Collaborator

systay commented Feb 26, 2020

Please re-open if it's not really fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants