1

First question here!

So I have a table with a row like this:

created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

I would like to run a query that delete all the data in my table older than 14 days.

This is my query:

DELETE FROM customers WHERE timestamp < NOW() - INTERVAL 14 DAY;

This is the error: syntax error at or near "14"

Anyone knows why this is not working and/or how could I achieve my goal??

Many thanks!!

0

3 Answers 3

1

The interval value must be quoted:

DELETE FROM customers WHERE created_at < NOW() - INTERVAL '14 DAYS';

See the doc

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

1 Comment

@LucaTomarelli: Instead of addin a "Thanks!" comment, it is custom here to upvote and/or accept an answer if it helped...
0
DELETE FROM customers WHERE created_at < NOW() - INTERVAL '14 DAY'; 

1 Comment

@LucaTomarelli: Instead of addin a "Thanks!" comment, it is custom here to upvote and/or accept an answer if it helped...
0

Another variation on the existing answers (possibly easier to remember):

DELETE FROM customers WHERE timestamp < NOW() - '14 days'::interval;

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.