Home > Blockchain >  I need to delete rows that are newer than 2019
I need to delete rows that are newer than 2019

Time:07-07

I am sending files from 12 years back to the server. For some reason, 2019 did not transfer in full and I have to remove it from DB. How to delete rows younger than 2018-12-30?

I try code below but i get error:

ERROR:  syntax error at or near "DELETE"
LINE 2: DELETE * FROM mlode WHERE "kd" > DATEFROMPARTS(2018, 12, 31)
        ^
SQL state: 42601

And this is code:

BEGIN TRANSACTION
DELETE * FROM mlode WHERE "kd" > DATEFROMPARTS(2018, 12, 31)
COMMIT TRANSACTION;

Any one knows what is wrong?

Ok I make progres. I changed the code to:

BEGIN TRANSACTION;
DELETE FROM mlode WHERE kd >= DATE '2019-01-01';
COMMIT TRANSACTION;

But now i get this error:

ERROR:  current transaction is aborted, commands ignored until end of transaction block

CodePudding user response:

It is not DELETE * FROM, but DELETE FROM.

DELETE FROM mlode WHERE kd >= DATE '2019-01-01';

CodePudding user response:

BEGIN TRANSACTION
DELETE FROM [TABLE] WHERE [DATEFIELD] > DATEFROMPARTS(2018, 12, 30)

COMMIT TRANSACTION
  • Related