0

I want to delete all records into Postgress table and leave only records which were created last 1 hour. I tried this:

DELETE FROM common.orders WHERE created_at < (NOW(), INTERVAL -1 HOUR);

But I get error:

[42601] ERROR: syntax error at or near "HOUR"

Do you know how I can fix this issue?

3
  • I think this post: stackoverflow.com/questions/30043431/… will answer your query Commented Oct 7, 2021 at 10:30
  • But I get error: [42601] ERROR: syntax error at or near "HOUR" 42601 is not documented SQLSTATE in MySQL. Moreover, there is no 42601 number on dev.mysql.com at all... And MySQL never uses double quote chars for keywords wrapping in its error messages. Commented Oct 7, 2021 at 11:10
  • I saw my mistake. The database is Postgress. I will update my question. Commented Oct 7, 2021 at 11:16

1 Answer 1

2

Move the minus outside of the INTERVAL clause. Also, the comma after NOW() should be removed as well, and the value for the unit needs to be specified in single quotes

DELETE FROM common.orders WHERE created_at < NOW() - INTERVAL '1 HOUR';
Sign up to request clarification or add additional context in comments.

1 Comment

Just a note, the ANSI SQL syntax is INTERVAL '1' HOUR.

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.