Skip to content

Commit

Permalink
fix table name for select only statement
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zhengda committed Aug 5, 2024
1 parent a44fe7c commit 90dbb27
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions normalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ multiline comment */
Size: 9,
},
},
{
input: "SELECT * FROM ONLY users WHERE id = ?",
expected: "SELECT * FROM ONLY users WHERE id = ?",
statementMetadata: StatementMetadata{
Tables: []string{"users"},
Comments: []string{},
Commands: []string{"SELECT"},
Procedures: []string{},
Size: 11,
},
},
}

normalizer := NewNormalizer(
Expand Down
23 changes: 23 additions & 0 deletions sqllexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,29 @@ func TestLexer(t *testing.T) {
{IDENT, "users"},
},
},
{
name: "select only",
input: "SELECT * FROM ONLY tab1 where id = 1",
expected: []Token{
{IDENT, "SELECT"},
{WS, " "},
{WILDCARD, "*"},
{WS, " "},
{IDENT, "FROM"},
{WS, " "},
{IDENT, "ONLY"},
{WS, " "},
{IDENT, "tab1"},
{WS, " "},
{IDENT, "where"},
{WS, " "},
{IDENT, "id"},
{WS, " "},
{OPERATOR, "="},
{WS, " "},
{NUMBER, "1"},
},
},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions sqllexer_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var tableIndicators = map[string]bool{
"EXISTS": true, // Drop Table If Exists
"STRAIGHT_JOIN": true, // MySQL
"CLONE": true, // Snowflake
"ONLY": true, // PostgreSQL
}

var keywords = map[string]bool{
Expand Down Expand Up @@ -147,6 +148,7 @@ var keywords = map[string]bool{
"OF": true,
"SKIP": true,
"IF": true,
"ONLY": true,
}

func isWhitespace(ch rune) bool {
Expand Down
20 changes: 20 additions & 0 deletions testdata/postgresql/select/select-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"input": "SELECT * FROM ONLY users, ONLY orders WHERE users.id = orders.user_id;",
"outputs": [
{
"expected": "SELECT * FROM ONLY users, ONLY orders WHERE users.id = orders.user_id",
"statement_metadata": {
"size": 17,
"tables": [
"users",
"orders"
],
"commands": [
"SELECT"
],
"comments": [],
"procedures": []
}
}
]
}

0 comments on commit 90dbb27

Please sign in to comment.