insert ... delete ... returning ... ?

Поиск
Список
Период
Сортировка
От Mark Mielke
Тема insert ... delete ... returning ... ?
Дата
Msg-id 47C1DFD7.7060603@mark.mielke.cc
обсуждение исходный текст
Ответы Re: insert ... delete ... returning ... ?  ("Guillaume Smet" <guillaume.smet@gmail.com>)
Re: insert ... delete ... returning ... ?  ("Jonah H. Harris" <jonah.harris@gmail.com>)
Список pgsql-hackers
Hi all:

I'm at PostgreSQL 8.3 for my production database and everything is 
working great. I had no problems converting free text search from 8.2 to 
8.3, and I really like the improvements.

I tried using insert ... delete ... return ... and get a syntax error:

> pccyber=# insert into product_manufacturer_archived (itemno, 
> manufacturer_id)
> pccyber-#   delete from product_manufacturer
> pccyber-#     where not exists (select * from icitem
> pccyber(#                         where icitem.itemno = 
> product_manufacturer.itemno and
> pccyber(#                               not inactive)
> pccyber-#     returning itemno, manufacturer_id;
> ERROR:  syntax error at or near "delete"
> LINE 2:   delete from product_manufacturer
>           ^

The goal here is to move inactive records to an archived table. This is 
to be performed as part of a daily batch job instead of as a trigger. 
Assume my model is correct - my question isn't how can I do this. I 
would like to know if insert .. delete .. returning is intended to work 
or not.

In the past I've executed insert ... select and then the delete. 
However, I believe there is race condition here as the delete may see 
more or less rows than the insert ... select. I thought the above would 
be a clever PostgreSQL-8.3 alternative, but I'm either stupid or it 
doesn't work... :-)

Any ideas?

Thanks,
mark

-- 
Mark Mielke <mark@mielke.cc>



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

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: Batch update of indexes on data loading
Следующее
От: "Guillaume Smet"
Дата:
Сообщение: Re: insert ... delete ... returning ... ?