-1

This question has been asked and answered before, but I am getting a syntax error with prior answers. Perhaps I am missing something?

query = "DELETE FROM currentvoltage WHERE timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW() - INTERVAL 1 DAY))"
cursor.execute(query)

currentvoltage is table

timestamp is row with timestamp in yyyy-mm-dd hh:mm:ss:ffff

Getting

42601 syntax error "at or near" the "1" for 1 Day

EDIT:

After everyone's assistance, the following was used.

query = "DELETE FROM {} WHERE timestamp < NOW() - INTERVAL '{} DAY'".format(tableName, truncate)
cursor.execute(query)

note: I am pulling the table name and the interval from global variables

BabaZuri
  • 19
  • 4

1 Answers1

0

Put 1 day in quotations (')

INTERVAL '1 DAY'

So finally

query = "DELETE FROM currentvoltage WHERE timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW() - INTERVAL '1 DAY'))"

Note that there is no function UNIX_TIMESTAMP & DATE_SUB in PgSQL

Sohel Ahmed Mesaniya
  • 3,344
  • 1
  • 23
  • 29