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

upsert doUpdate max not matching readme? #1743

Open
jubishop opened this issue Mar 11, 2025 · 2 comments
Open

upsert doUpdate max not matching readme? #1743

jubishop opened this issue Mar 11, 2025 · 2 comments

Comments

@jubishop
Copy link

in the readme I can't seem to make this work:

Column("date").set(to: max(Column("date"), excluded["date"])

it appears I can only specify one argument to max or a second with the keyword filter. Am I missing something?

thanks!

@groue
Copy link
Owner

groue commented Mar 12, 2025

Hello @jubishop,

Thank you for the report! This is both a documentation bug, and a missing feature.

The sample code is misleading, because GRDB does not ship with the MAX(X,Y,...) multi-argument function. When one writes max, it refers to the MAX(X) aggregate function.

If you need the multi-argument function right now, you can define it yourself, until the library ships a new version that includes it:

func max(
    _ arg1: any SQLSpecificExpressible,
    _ arg2: any SQLExpressible,
    _ args: any SQLExpressible...
) -> SQLExpression {
    var sql: SQL = "MAX(\(arg1), \(arg2)"
    for arg in args {
        sql += ", \(arg)"
    }
    sql += ")"
    return sql.sqlExpression
}

@jubishop
Copy link
Author

Ahh that makes sense thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants