MCPcopy Create free account
hub / github.com/PostHog/duckgres / constraintErrorCode

Function constraintErrorCode

server/conn_errors.go:226–239  ·  view source on GitHub ↗

constraintErrorCode narrows a "Constraint Error: …" message to one of the integrity_constraint_violation family codes. DuckDB's messages name the violated constraint explicitly, so substring matching is reliable.

(msg string)

Source from the content-addressed store, hash-verified

224// integrity_constraint_violation family codes. DuckDB's messages name the
225// violated constraint explicitly, so substring matching is reliable.
226func constraintErrorCode(msg string) string {
227 lower := strings.ToLower(msg)
228 switch {
229 case strings.Contains(lower, "duplicate key") || strings.Contains(lower, "unique"):
230 return "23505" // unique_violation
231 case strings.Contains(lower, "not null") || strings.Contains(lower, "null value"):
232 return "23502" // not_null_violation
233 case strings.Contains(lower, "foreign key"):
234 return "23503" // foreign_key_violation
235 case strings.Contains(lower, "check constraint"):
236 return "23514" // check_violation
237 }
238 return "23000" // integrity_constraint_violation
239}
240
241// userErrorSQLSTATEClasses is the closed set of PostgreSQL SQLSTATE class
242// codes (the first two characters) that represent user-input or

Callers 1

classifyErrorCodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected