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)
| 224 | // integrity_constraint_violation family codes. DuckDB's messages name the |
| 225 | // violated constraint explicitly, so substring matching is reliable. |
| 226 | func 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 |