0

I need to delete all entries in a table where the active column is false and that the expire date being 30 days back or more from current date. But how do I add the 30 days to the timestamp in where CLAUSE? I tried this but get a malformed SQL exception

DELETE * FROM share
         WHERE active = false
         AND (expire + 30) > UNIX_TIMESTAMP();

I could not get timestampadd to work either.

2
  • What is your expire column data type? Commented Jan 23, 2018 at 9:53
  • It is timestamp Commented Jan 23, 2018 at 10:00

2 Answers 2

1
 DELETE FROM share
 WHERE active = false
 AND from_unixtime(expire) + interval 30 day > curr_date();

or since unix time is in seconds:

 DELETE FROM share
 WHERE active = false
 AND expire + (30*86400) > UNIX_TIMESTAMP();
Sign up to request clarification or add additional context in comments.

Comments

0

So, to make sure that MySQL can actually use indexes, you should do something like this:

DELETE FROM share WHERE active = false AND expire <= UNIX_TIMESTAMP() - 30 * 24 * 3600;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.