Can I use SQLite math extension in GRDB? #1551
Unanswered
orkhanalizada2020
asked this question in
Q&A
Replies: 1 comment
-
Hello @orkhanalizada2020, I suppose you're talking about the Built-In Mathematical SQL Functions. If SQLite is built with support for those functions, then you can use them, as all SQL functions. You can use raw SQL (see Embedding SQL in Query Interface Requests): // SELECT sin(angle), pow(width, 2) FROM shape
let request = Shape.select(sql: "sin(angle), pow(width, 2)") You can also define Swift versions on the SQL functions needed by your app, as below: func sin(_ value: some SQLSpecificExpressible) -> SQLExpression {
SQL("sin(\(value))").sqlExpression
}
func pow(_ x: some SQLSpecificExpressible, _ y: some SQLExpressible) -> SQLExpression {
SQL("pow(\(x), \(y))").sqlExpression
}
// SELECT sin(angle), pow(width, 2) FROM shape
let request = Shape.select(sin(Column("angle")), pow(Column("width"), 2)) Take care, as in the sample code, to use sin(2) // The regular Swift sine function, not an SQL expression
sin(Column("angle")) // An SQL expression
pow(Column("width"), 2) // An SQL expression |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to use SQLite math extension in GRDB. Is it possible? If yes, any hint on how can I achieve that?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions