Re: perform 1 check vs exception when unique_violation
В списке pgsql-performance по дате отправления:
| От | Robert Haas |
|---|---|
| Тема | Re: perform 1 check vs exception when unique_violation |
| Дата | |
| Msg-id | 603c8f070812300650i226f032co8db1f25eb352e4b8@mail.gmail.com обсуждение |
| Ответ на | perform 1 check vs exception when unique_violation (Anton Bogdanovitch <poison.box@gmail.com>) |
| Список | pgsql-performance |
On Tue, Dec 30, 2008 at 5:41 AM, Anton Bogdanovitch <poison.box@gmail.com> wrote: > I have to insert rows to table with 95% primary key unique_violation. If you're inserting a lot of rows at once, I think you're probably better off loading all of the data into a side table that does not have a primary key, and then writing one statement to remove the duplicates and do all the inserts at once. INSERT INTO main (name, created) SELECT s.name, CURRENT_TIMESTAMP FROM (SELECT DISTINCT ON (name) FROM sidetable) s -- nuke duplicate names within sidetable LEFT JOIN main m ON s.name = m.name WHERE m.name IS NULL; -- nuke names in sidetable that are already in main I've usually found that any kind of loop in PL/pgsql is mind-numbingly slow compared to doing the same thing as a single query. ...Robert
В списке pgsql-performance по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера