1

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.

Xkid
  • 338
  • 1
  • 4
  • 17
  • https://stackoverflow.com/questions/27080505/dateadd-equivalent-in-postgresql – Luuk Jun 16 '21 at 21:39
  • Does this answer your question? [Postgres INTERVAL using value from table](https://stackoverflow.com/questions/26979764/postgres-interval-using-value-from-table) – David Brossard Jun 16 '21 at 21:42

1 Answers1

4

Try this:

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

You can find the documentation here.

enter image description here

armandino
  • 17,625
  • 17
  • 69
  • 81