Reputation: 15491
Using this query:
users = User.where('confirmed_at is NULL AND confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL ? days)', 1)
In mysql goes okay but in Postgresql it fails with:
PG::SyntaxError: ERROR: syntax error at or near "1" LINE 1: ...AND confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL 1 day)) ^ : SELECT "users".* FROM "users" WHERE (confirmed_at is NULL AND confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL 1 day))
I'm trying to understand but missing the context here. Why is the integer 1 not valid in this query?
Upvotes: 1
Views: 1183
Reputation: 656351
There is no function DATE_SUB()
in PostgreSQL, so it cannot work.
This expression would work in Postgres:
... AND confirmation_sent_at <= (now() - interval '1 day')
Or, if confirmation_sent_at
is a date
:
... AND confirmation_sent_at <= (now()::date - 1)
Upvotes: 3
Reputation: 5973
Try...
users = User.where(
"confirmed_at IS NULL " +
"AND confirmation_sent_at <= (NOW() - INTERVAL '1 DAY')"
)
Upvotes: 1