Обсуждение: Issue with delete

Поиск
Список
Период
Сортировка

Issue with delete

От
Rohit Rajput
Дата:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);

where i run this, i get following error:

    Error: current transaction is aborted, commands ignored until end of transaction block.
SQL state: 25P02.


I am running it in RDS.


TIA, Best,
Rohit

Re: Issue with delete

От
Holger Jakobs
Дата:
Am 24.06.21 um 11:08 schrieb Rohit Rajput:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);

where i run this, i get following error:

    Error: current transaction is aborted, commands ignored until end of transaction block.
SQL state: 25P02.


I am running it in RDS.


TIA, Best,
Rohit

This message stems from a previous error within the same transaction. Unlike Oracle, PostgreSQL cannot execute commands within a transaction after an error has occurred.

Make sure that this statement is the first in your transaction or use it in autocommit mode.


-- 
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
Вложения

Re: Issue with delete

От
Rohit Rajput
Дата:
Thanks Holger. My bad. appreciate it.

On Thursday, 24 June, 2021, 02:53:02 pm IST, Holger Jakobs <holger@jakobs.com> wrote:


Am 24.06.21 um 11:08 schrieb Rohit Rajput:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);

where i run this, i get following error:

    Error: current transaction is aborted, commands ignored until end of transaction block.
SQL state: 25P02.


I am running it in RDS.


TIA, Best,
Rohit

This message stems from a previous error within the same transaction. Unlike Oracle, PostgreSQL cannot execute commands within a transaction after an error has occurred.

Make sure that this statement is the first in your transaction or use it in autocommit mode.


-- 
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012

Re: Issue with delete

От
"Radoulov, Dimitre"
Дата:


Am 24.06.21 um 11:08 schrieb Rohit Rajput:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);


Wouldn't "delete from mytable where condition=true limit 1000" be sufficient?


Regards
Dimitre

Re: Issue with delete

От
Guillaume Lelarge
Дата:
Le jeu. 24 juin 2021 à 16:02, Radoulov, Dimitre <cichomitiko@gmail.com> a écrit :


Am 24.06.21 um 11:08 schrieb Rohit Rajput:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);


Wouldn't "delete from mytable where condition=true limit 1000" be sufficient?



That syntax doesn't exist.


--
Guillaume.

Re: Issue with delete

От
"Radoulov, Dimitre"
Дата:
On 24/06/2021 16.48, Guillaume Lelarge wrote:
Le jeu. 24 juin 2021 à 16:02, Radoulov, Dimitre <cichomitiko@gmail.com> a écrit :


Am 24.06.21 um 11:08 schrieb Rohit Rajput:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);


Wouldn't "delete from mytable where condition=true limit 1000" be sufficient?



That syntax doesn't exist.


I should have tried the statement before asking, thanks!
I got confused by other databases (used it on Db2).


Best regards
Dimitre

Re: Issue with delete

От
Keith
Дата:


On Thu, Jun 24, 2021 at 5:08 AM Rohit Rajput <rht.rajput@yahoo.com> wrote:
Good day everyone,

I have few tables where i need to delete above 50 million rows each. Since i dont want to delete them all in one shot and block my table for extended time, i am trying to use limit with delete but its giving me error every time. May i please get some assistance here? Thanks

Here is what i am running:

delete from mytable where id in (select id from mytable where condition=true limit 1000);

where i run this, i get following error:

    Error: current transaction is aborted, commands ignored until end of transaction block.
SQL state: 25P02.


I am running it in RDS.


TIA, Best,
Rohit

As others said, there is no limit with the UPDATE/DELETE statements in PostgreSQL. However, you can get around that using a common table expression (CTE). We have a blog post on doing exactly this up at CrunchyData


Keith