duplicate

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package duplicate parses PostgreSQL unique violation errors (SQLSTATE 23505) of lib/pq.

Most code should use sqlkit.IsDuplicate and sqlkit.DuplicateFields instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDetail

func ParseDetail(detail string) (fields []string, value string, ok bool)

ParseDetail parses the Detail of a unique violation: "Key (a, b)=(x, y) already exists.".

fields are the names inside the first parentheses split by ", "; value is the whole content of the second parentheses (values may contain commas). An index expression such as "lower(name::text)" is returned as a single field as is. ok is false if detail is not recognized.

Types

type Error

type Error struct {
	// Field is the column guessed from the constraint name ("users_email_key" -> "email").
	Field string
	// Value is the duplicated value taken from the error detail.
	Value string
	// Constraint is the name of the violated constraint.
	Constraint string
}

Error describes a unique violation.

func Handle

func Handle(err *pq.Error) *Error

Handle extracts the field, value and constraint of a unique violation from err.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL