I've got a postgres table with user records in it. I want to select all records where the last_visit timestamp is within the last week OR the account was created in the last week. However, if a user hasn't visited yet, the last_visit timestamp is null (yeah, I know-- it's not set to default to the account creation date).
So I need to select all records WHERE either the last_visit is in the last week OR, if that's null, where creation_date is in the last week.
Something like this, although this doesn't work (and neither does a dozen other possible syntaxes I've tried:
SELECT * FROM users
WHERE
IF (users.last_active IS NULL) THEN
value(users.last_visit,timestamp(users.creation_date)) < current timestamp - 7 days
ELSE
users.last_active < current timestamp - 7 days
END IF
Any advice?