Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
22 changes: 21 additions & 1 deletion sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ var (
output: "select /* string table alias */ 1 from t as 't1'",
// mysql allow to use single quote for column/table aliases
dialect: mysql.NewMySQLDialect(),
}, {
input: `select * from mytable where "AGE" = 1 and "TEST" = 'test'`,
// postgres allow to use double quote string for columns
dialect: postgresql.NewPostgreSQLDialect(),
}, {
input: `select * from mytable where "test" = "test"`,
output: `select * from mytable where 'test' = 'test'`,
}, {
input: `select * from mytable where "test" = 1 and 'value' = 'value'`,
output: `select * from mytable where 'test' = 1 and 'value' = 'value'`,
}, {
input: `SELECT "id", "landline_number" AS "landlineNumber", "removal" FROM "users" AS "User" where "User"."is_active"`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add some somparison too: WHERE "User"."AGE" = 123 and simple "AGE"='123' without table name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus I remember that you mentioned some integration tests with double quotes. Can we extend them with additional cases that we caught?

output: `select "id", "landline_number" as "landlineNumber", "removal" from "users" as "User" where "User"."is_active"`,
dialect: postgresql.NewPostgreSQLDialect(),
}, {
input: "select /* string table alias without as */ 1 from t 't1'",
output: "select /* string table alias without as */ 1 from t as 't1'",
Expand Down Expand Up @@ -1322,11 +1336,17 @@ var (
)

func TestValid(t *testing.T) {
var testDialect dialect.Dialect
for i, tcase := range validSQL {
if tcase.output == "" {
tcase.output = tcase.input
}
tree, err := New(ModeStrict).Parse(tcase.input)

testDialect = tcase.dialect
if tcase.dialect == nil {
testDialect = mysql.NewMySQLDialect()
}
tree, err := ParseWithDialect(testDialect, tcase.input)
if err != nil {
t.Errorf("Parse(%q) err: %v, want nil", tcase.input, err)
continue
Expand Down
Loading