How to inspect the condition on a partial index? #1829
Answered
by
groue
grantneufeld
asked this question in
Q&A
-
|
I am creating a partial index. try db.create(
index: "myIndex",
on: "myTable",
columns: ["someColumn", "anotherColumn"],
condition: "WHERE someColumn IS NOT NULL"
)When I get // code fragment from using swift-testing in to validate:
let indexes = try db.indexes(on: "myTable")
for index in indexes {
if index.name == "myIndex" {
#expect(index.isUnique == false) // passes
#expect(index.columns == ["someColumn", "anotherColumn"]) // passes
// But there is no `index.condition`, or such, to use here.
// The only other property available on index is `origin`,
// which, in my testing, just evaluates to `"c"`.
}
}So, is there a way I can find the |
Beta Was this translation helpful? Give feedback.
Answered by
groue
Oct 25, 2025
Replies: 1 comment 1 reply
-
|
Hello @grantneufeld, SQLite does not provide this information: In order to test the schema, I'd instead suggest to test the content of let sql = try String.fetchOne(db, sql: "select sql from sqlite_master where name = 'myIndex'")
#expect(sql == "CREATE INDEX myIndex on player(name) where score is not null")You can also use the companion library GRDBSnapshotTesting. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
grantneufeld
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @grantneufeld,
SQLite does not provide this information:
In order to test the schema, I'd instead suggest to test the content of
sqlite_master: