Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

upsert-patterns

/upsert-patterns

Pokazuje, jak wstawiać lub aktualizować rekordy jednym zapytaniem bez wyścigów i utraconych aktualizacji, z użyciem obsługi konfliktów silnika zamiast sprawdzania przed zapisem.

Repozytorium
AI-SKILLS ↗
Licencja
MIT
Ostatnia zmiana repozytorium
05.09.2026

Ocena i bezpieczeństwo

90/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść25 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 05.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pokazuje, jak wstawiać lub aktualizować rekordy jednym zapytaniem bez wyścigów i utraconych aktualizacji, z użyciem obsługi konfliktów silnika zamiast sprawdzania przed zapisem.

Oryginalny opis (EN)

Insert or update in one statement without races or lost updates, using the engine's conflict handling rather than check-then-write. Use when writing records that may or may not already exist.

Jak działa

  1. Method
  2. Boundaries
Sekcje z nagłówków SKILL.md, w oryginale · 39 linii, 275 słów
Podgląd SKILL.md
---
name: upsert-patterns
description: Insert or update in one statement without races or lost updates, using the engine's conflict handling rather than check-then-write. Use when writing records that may or may not already exist.
---

# Upsert patterns

The naive approach, checking whether a row exists and then inserting or
updating, is a race in every concurrent system: two callers both check,
both find nothing, and one insert fails or duplicates. Upsert exists so
the database resolves that atomically.

## Method

1. **Use the engine's conflict clause.** ON CONFLICT, MERGE, or the
   equivalent performs the decision inside one statement, which is what
   makes it safe under concurrency.
2. **Target a real unique constraint.** Conflict handling needs a
   constraint to detect against, so the uniqueness must exist in the
   schema rather than in your intent.
3. **Decide what update means on conflict.** Overwrite everything, merge
   selected columns, or do nothing. Blindly overwriting can discard
   concurrent changes made between read and write (see
   transactions-isolation).
4. **Preserve creation metadata.** created_at and similar columns should
   not be overwritten by the update branch, which is an easy detail to
   miss and hard to notice later.
5. **Make bulk upserts deterministic.** A batch containing two rows with
   the same key needs a defined winner, since some engines error and
   others pick arbitrarily.
6. **Consider idempotency for retried writes.** An upsert keyed on a
   natural or client-supplied key makes a retried request safe, which is
   what you want in any queue or API path (see idempotency).

## Boundaries

- Upsert resolves existence races; it does not resolve semantic
  conflicts about which version of the data is correct.
- Conflict syntax and behaviour differ substantially between engines, so
  this is one of the less portable parts of SQL.
- Heavy upsert traffic on the same keys creates contention, which is a
  throughput problem rather than a correctness one.

Wersje

W bazie nie ma innych skilli o nazwie upsert-patterns.

Migawka bazy z 13.11.2026 · wersja paczki 4e0a7c010c43 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100yida-business-rule
    Konfiguruje w formularzach Yida reguły powiązań biznesowych i funkcje INSERT, UPDATE, DELETE i UPSERT do zmian między tabelami.
  • 84crud-ops
    Pokazuje wzorce operacji CRUD w ScalarDB, czyli buildery Get, Scan, Insert, Upsert, Update i Delete, z przykładami.
  • 100t-sql-upserts-merge
    Pisze bezpieczny upsert dla Azure SQL Database, odporny na równoczesne sesje, i odrzuca warianty MERGE gubiące wiersze.
  • 84jdbc-ops
    Pokazuje wzorce operacji SQL/JDBC w ScalarDB: SELECT, INSERT, UPSERT, UPDATE, DELETE, JOIN i agregaty, z ograniczeniami.
  • 93writing-sql
    Pisze zapytania SQL dla eksportów i importów Celigo RDBMS: SELECT, INSERT, UPSERT, MERGE i operacje masowe.
  • 100mariadb-replace
    Opisuje działanie REPLACE w MariaDB jako usunięcie z następującym wstawieniem, ryzyko utraty danych, alternatywę INSERT ON DUPLICATE KEY UPDATE oraz formy RETURNING i SET.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.