Исходный код вики Insert or update. Upsert
Редактировал(а) Alexandr Fokin 2024/06/01 12:59
Последние авторы
author | version | line-number | content |
---|---|---|---|
1 | | |(% style="width:322px" %)insert on conflict|(% style="width:1050px" %) | ||
2 | |If not exist|(% style="width:322px" %){{code language="sql"}}INSERT INTO table1 | ||
3 | (id) | ||
4 | SELECT 1 | ||
5 | WHERE | ||
6 | NOT EXISTS ( | ||
7 | SELECT 1 | ||
8 | FROM table1 | ||
9 | WHERE id = 1 | ||
10 | ) | ||
11 | ON CONFLICT DO NOTHING{{/code}}|(% style="width:1050px" %)((( | ||
12 | Конструкция {{code language="sql"}}ON CONFLICT{{/code}} не защищает от обращения к генератору ключа (sequence). И это может привести к тому, что счетчик будет крутиться впустую. | ||
13 | Использование выборки с условием не убирает полностью ложные срабатывания (если они проходя одновременно), но после вставки записи, обращения к генератору прекратятся. | ||
14 | |||
15 | |||
16 | PostgreSQL Antipatterns: накручиваем себе проблемы | ||
17 | [[https:~~/~~/habr.com/ru/companies/tensor/articles/507688/>>url:https://habr.com/ru/companies/tensor/articles/507688/]] | ||
18 | \\Postgres: INSERT if does not exist already | ||
19 | [[https:~~/~~/stackoverflow.com/questions/4069718/postgres-insert-if-does-not-exist-already>>url:https://stackoverflow.com/questions/4069718/postgres-insert-if-does-not-exist-already]] | ||
20 | ))) | ||
21 | | |(% style="width:322px" %) |(% style="width:1050px" %) | ||
22 | |||
23 | ---- | ||
24 | |||
25 | ==== Внутренние ссылки: ==== | ||
26 | |||
27 | ====== Дочерние страницы: ====== | ||
28 | |||
29 | {{children/}} | ||
30 | |||
31 | ====== Обратные ссылки: ====== | ||
32 | |||
33 | {{velocity}} | ||
34 | #set ($links = $doc.getBacklinks()) | ||
35 | #if ($links.size() > 0) | ||
36 | #foreach ($docname in $links) | ||
37 | #set ($rdoc = $xwiki.getDocument($docname).getTranslatedDocument()) | ||
38 | * [[$escapetool.xml($rdoc.fullName)]] | ||
39 | #end | ||
40 | #else | ||
41 | No back links for this page! | ||
42 | #end | ||
43 | {{/velocity}} | ||
44 | |||
45 | ---- |