Skip to content

DB.onconflict() requires a primary key #56

Closed

Description

@justinpryzby

It'd be more flexible and simpler to pass to postgres the list of columns or index name itself. But I guess you'd want to continue supporting the old way, too, so it wouldn't actually simplify anything.

I noticed this while adding something similar in telsasoft-specific db layer. We use unique indexes but not primary keys. There may be other reasons why we wouldn't use DB.insert(), too, but it'd be nice if this supported non-primary keys, and also multiple combinations of unique indexes.

Edit: of course I mean DB.upsert()
Edit: also, ON CONFLICT DO NOTHING needs no pkey nor columns nor unique index at all (even though in my experience that may be a bad idea since if an unique index is missing it causes no error)
Edit: also, ON CONFLICT allows WHERE clauses in two different places (in the ON CONFLICT and in the DO UPDATE SET). And some other syntactic cases. But, I'm actually using the where clauses now, but some of these are maybe "pie in the sky" and maybe of maybe marginal value.

Activity

  1. added this to the 6.1 milestone on Aug 27, 2023
  2. modified the milestones: 6.1, 6.2 on Dec 5, 2024
  3. modified the milestones: 6.2, 6.3 on Nov 20, 2026
  4. Cito commented on Nov 22, 2026

    @Cito
    Member

    DB.upsert(), DB.update() and DB.delete() now have an optional keyname parameter like DB.get() (#127, in 6.3). It is a column name or a sequence of names, so these methods also work for tables without a primary key. For upsert() it is the conflict target. ON CONFLICT DO NOTHING without a target, constraint names and WHERE clauses are not supported. The awkward use of keyword arguments in these methods is discussed for 7.0 in #126.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions