Xkid
Xkid

Reputation: 409

PostgreSQL: how to delete rows from a table older than 2 months?

I've the next data table:

customer category date_column
01 A 2021/06/16
02 B 2021/04/15
03 C 2021/03/15

I would like to create query that would delete rows from this data table older than 2 months and here is my try:

DELETE * FROM schema.table
WHERE DATEADD(Month,2,date_column) < getdate()

By now I've been trying to use DATEADD to make it but seems that this function doesn't work in PostgreSQL. Could you hel me, guys?

This would be the desired output:

customer category date_column
01 A 2021/06/16

Thanks by the way.

Upvotes: 1

Views: 9346

Answers (1)

armandino
armandino

Reputation: 18538

Try this:

DELETE * FROM schema.table
WHERE date_column < CURRENT_DATE - interval '2 month';

You can find the documentation here.

enter image description here

Upvotes: 6

Related Questions