Skip to content

Commit

Permalink
pgsql: add IsSerializationFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Aug 2, 2023
1 parent 2619233 commit f5ca40f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ func IsForeignKeyViolation(err error, constraint ...string) bool {
// IsQueryCanceled checks is error an query_canceled error
// (pq: canceling statement due to user request)
func IsQueryCanceled(err error) bool {
var pqErr *pq.Error
if errors.As(err, &pqErr) && pqErr.Code == "57014" {
return true
}
return false
return IsErrorCode(err, "57014")
}

// IsSerializationFailure checks is error an serialization_failure error
// (pq: could not serialize access due to read/write dependencies among transactions)
func IsSerializationFailure(err error) bool {
return IsErrorCode(err, "40001")
}

func extractConstraint(err *pq.Error) string {
Expand Down

0 comments on commit f5ca40f

Please sign in to comment.