Luca Tomarelli
Luca Tomarelli

Reputation: 11

PostgreSQL: Syntax error at or near "14" when trying to run a delete query

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!!

Upvotes: 1

Views: 574

Answers (3)

Tom
Tom

Reputation: 580

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

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

Upvotes: 0

Tryph
Tryph

Reputation: 6209

The interval value must be quoted:

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

See the doc

Upvotes: 1

wildplasser
wildplasser

Reputation: 44250

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

Upvotes: 0

Related Questions