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

[postgres] fix table name for select only statement #36

Merged
merged 1 commit into from
Aug 5, 2024
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
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": []
}
}
]
}
Loading