Re: BUG #15737: Unexpectedly Deleting full table when referring CTE(With Clause ) data,in a Subquery in another CTE

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: BUG #15737: Unexpectedly Deleting full table when referring CTE(With Clause ) data,in a Subquery in another CTE
Дата
Msg-id CAKJS1f8E=LMLKgwFWY3DH0jRfsQwYeixxjQVG++0WsLzLf=MAQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: BUG #15737: Unexpectedly Deleting full table when referring CTE(With Clause ) data,in a Subquery in another CTE  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: BUG #15737: Unexpectedly Deleting full table when referring CTE(With Clause ) data,in a Subquery in another CTE  (Chandan Ahuja <chandanahuja7@gmail.com>)
Список pgsql-bugs
On Fri, 5 Apr 2019 at 09:26, David G. Johnston
<david.g.johnston@gmail.com> wrote:
>
> On Thu, Apr 4, 2019 at 1:08 PM PG Bug reporting form <noreply@postgresql.org> wrote:
>> -- I am referring contract_id column here from deletedata but it does not
>> exist
>> delete from core.contract where contract_id in ( select distinct contract_id
>> from deletedata) -- returning contract_id
>
>
> No bugs; its just the hard (but common) way to really learn the difference between a correlated subquery and an
independentone; and to test your deletion queries thoroughly before running them live.
 

Ouch! ... the hard way to learn to always give your tables an alias
and prefix the column names with them.

There are cases where it could also happen if a column is dropped.
Best not to leave these landmines laying around:

postgres=# delete from t1 where b in(select b from t2);
DELETE 0
postgres=# alter table t2 drop column b;
ALTER TABLE
postgres=# delete from t1 where b in(select b from t2);
DELETE 1000

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services



В списке pgsql-bugs по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: BUG #15737: Unexpectedly Deleting full table when referring CTE(With Clause ) data,in a Subquery in another CTE
Следующее
От: Amit Langote
Дата:
Сообщение: Re: BUG #15733: An insert destined at partition created after acolumn has been dropped from the parent table fails