Skip to content

Commit

Permalink
Use raw SQL for indexes on expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed Dec 21, 2024
1 parent 9b0dec7 commit 5469ddc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql2pgroll/create_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func canConvertCreateIndexStmt(stmt *pgq.IndexStmt) bool {
if stmt.GetIfNotExists() {
return false
}
// Indexes defined on expressions are not supported
for _, node := range stmt.GetIndexParams() {
if node.GetIndexElem().GetExpr() != nil {
return false
}
}

for _, param := range stmt.GetIndexParams() {
if param.GetIndexElem().GetCollation() != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql2pgroll/create_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func TestUnconvertableCreateIndexStatements(t *testing.T) {
"CREATE INDEX idx_name ON foo(a) NULLS NOT DISTINCT",
// IF NOT EXISTS is unsupported
"CREATE INDEX IF NOT EXISTS idx_name ON foo(a)",
// Indexes defined on expressions are not supported
"CREATE INDEX idx_name ON foo(LOWER(a))",
"CREATE INDEX idx_name ON foo(a, LOWER(b))",
}

for _, sql := range tests {
Expand Down

0 comments on commit 5469ddc

Please sign in to comment.