@@ -211,6 +211,33 @@ var (
211211 output : "select /* string table alias */ 1 from t as 't1'" ,
212212 // mysql allow to use single quote for column/table aliases
213213 dialect : mysql .NewMySQLDialect (),
214+ }, {
215+ input : `select * from mytable where "AGE" = 1 and "TEST" = 'test'` ,
216+ // postgres allow to use double quote string for columns
217+ dialect : postgresql .NewPostgreSQLDialect (),
218+ }, {
219+ // this is valid query ONLY for MySQL in default mode, for now,
220+ // but invalid for PostgreSQL and MySQL in ANSI mode and maybe be changed in future
221+ input : `insert into some_table(id, data) VALUES (10918, "test")` ,
222+ output : `insert into some_table(id, data) values (10918, 'test')` ,
223+ }, {
224+ input : `insert into some_table(id, data) values (10918, 'test')` ,
225+ }, {
226+ input : `select * from mytable where "test" = "test"` ,
227+ output : `select * from mytable where 'test' = 'test'` ,
228+ }, {
229+ input : `select * from mytable where "test" = 1 and 'value' = 'value'` ,
230+ output : `select * from mytable where 'test' = 1 and 'value' = 'value'` ,
231+ }, {
232+ input : `SELECT "id", "landline_number" AS "landlineNumber", "removal" FROM "users" AS "User" where "User"."is_active"` ,
233+ output : `select "id", "landline_number" as "landlineNumber", "removal" from "users" as "User" where "User"."is_active"` ,
234+ dialect : postgresql .NewPostgreSQLDialect (),
235+ }, {
236+ input : `select "id" from "users" as "User" where "User"."AGE" = 123` ,
237+ dialect : postgresql .NewPostgreSQLDialect (),
238+ }, {
239+ input : `select "id" from "users" as "User" where "AGE" = '123'` ,
240+ dialect : postgresql .NewPostgreSQLDialect (),
214241 }, {
215242 input : "select /* string table alias without as */ 1 from t 't1'" ,
216243 output : "select /* string table alias without as */ 1 from t as 't1'" ,
@@ -1322,11 +1349,17 @@ var (
13221349)
13231350
13241351func TestValid (t * testing.T ) {
1352+ var testDialect dialect.Dialect
13251353 for i , tcase := range validSQL {
13261354 if tcase .output == "" {
13271355 tcase .output = tcase .input
13281356 }
1329- tree , err := New (ModeStrict ).Parse (tcase .input )
1357+
1358+ testDialect = tcase .dialect
1359+ if tcase .dialect == nil {
1360+ testDialect = mysql .NewMySQLDialect ()
1361+ }
1362+ tree , err := ParseWithDialect (testDialect , tcase .input )
13301363 if err != nil {
13311364 t .Errorf ("Parse(%q) err: %v, want nil" , tcase .input , err )
13321365 continue
@@ -1656,6 +1689,9 @@ func TestConvert(t *testing.T) {
16561689 input : "select convert('abc', decimal(4+9)) from t" ,
16571690 output : "syntax error at position 33" ,
16581691 },
1692+ // TODO: added test cases to cover errors for MySQL ANSI mode
1693+ // `insert into table (id, name) values (125, "data")` currently, in ANSI mod its valid query with contains
1694+ // Rows {SQLVal(125), ColName("data")} - but it should fail with error
16591695 }
16601696
16611697 var dialect dialect.Dialect
0 commit comments