2

My Android app has an SQLite database table with entries as follows:

USER_ID | NAME | MESSAGE | TIMESTAMP

where the timestamp is stored in a String in format:

"2012-10-10T03:14:32+0000"

I'm looking for a way to delete entries older than 3 days.

The table is likely to have less than 3,000 rows at a time.

I'm new to SQL and my question is how can I approach this in SQL for SQLite? Is there a less expensive way to do this in SQL than to iterate all posts in Java?

1

1 Answer 1

3

You can have a look at this doc.

Another way is to use the fact that the date format you use can be sorted directly as a string (lexicographical order).

  1. In java code, you build the string representing the datetime threshold (Now minus 3 days)
  2. And just compare the strings in SQL in the where clause

    SELECT * FROM MyTable WHERE TIMESTAMP >= 'The date I built in Java'

Most of the time, Timestamps and datetimes are stored as ticks in SQLite, which involves int comparaison (much faster).

Sign up to request clarification or add additional context in comments.

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.