F
F
fr0zen2017-10-16 16:53:58
PostgreSQL
fr0zen, 2017-10-16 16:53:58

How to remove subquery data in postgres?

I have a subquery, how can I remove the data that is in it from the table?
Tried to do it like this but it doesn't work

with to_del as (
select * from Chat where Subject='427c6f3e-9876-48c5-b44d-776771f7c2c9')
delete from to_del

UDP: There is a situation where the chat has 100500 messages. we want to delete this chat. try to delete everything with one request - everything will be blocked, the work will stop. There is a desire to delete in portions, after deleting each portion, the sql query should return the number of records that has now been deleted. The business logic will spin the sql script until the returned value is zero.
Therefore, I want to make a subquery with a limit, give it for deletion and return the number of records. If there are other solutions - wellcome.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-10-16
@fr0zen

delete from Чат where id IN (select id from Чат where Тема='427c6f3e-9876-48c5-b44d-776771f7c2c9' LIMIT 1000)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question