DT
Drizzle Team•2mo ago
roze789

How to apply "where OR condition" and "lt or gt condition" on timestamp fields

Hello, i woud like to apply 2 conditions: - OR condition - if basketItem invoicedOn is newer than basketItem InvoicedOn with 1 hour added to it Have you any idea ?
No description
No description
9 Replies
Mario564
Mario564•2mo ago
@roze789 You should use the sql operator on at least one of the two arguments, since these boolean operators expect for at least one side to be a SQL expression
roze789
roze789OP•2mo ago
ok and how do i add 1 hour to a timestamp field please ?
Mario564
Mario564•2mo ago
You can do this:
sql`${basketsItems.invoicedOn} + interval '1 hour'`;
sql`${basketsItems.invoicedOn} + interval '1 hour'`;
roze789
roze789OP•2mo ago
thank I did work. I have another question left then I stop 🥲
roze789
roze789OP•2mo ago
How do i apply OR condition ?
No description
Mario564
Mario564•2mo ago
That should be correct. What's the type error?
roze789
roze789OP•2mo ago
Argument of type 'SQL<unknown> | undefined' is not assignable to parameter of type 'SQL<unknown>'.
Type 'undefined' is not assignable to type 'SQL<unknown>'.ts(2345)
Argument of type 'SQL<unknown> | undefined' is not assignable to parameter of type 'SQL<unknown>'.
Type 'undefined' is not assignable to type 'SQL<unknown>'.ts(2345)
Mario564
Mario564•2mo ago
If or has 0 conditions, it will return undefined, hence why it returns SQL | undefined. You can do two things here: Add or(...)! to eliminate the undefined (since in this case, we know there will be conditions) or type filters as (SQL | undefined)[]
roze789
roze789OP•2mo ago
Thank you, used the second option. It works.

Did you find this page helpful?