On Appendix A: PostgreSQL error codes, it says:
For some types of errors, the server reports the name of a database object (a table, table column, data type, or constraint) associated with the error; for example, the name of the unique constraint that caused a unique_violation error. Such names are supplied in separate fields of the error report message so that applications need not try to extract them from the possibly-localized human-readable text of the message.
Bold emphasis mine. I have the following table:
CREATE TABLE recipes (
id SERIAL,
title TEXT UNIQUE NOT NULL,
description TEXT NOT NULL,
instructions TEXT NOT NULL,
image BYTEA,
CONSTRAINT recipes_pk PRIMARY KEY(id),
CONSTRAINT title_unique UNIQUE(title)
);
When I try to insert a new row with a duplicate title, I get the following error message in pgAdmin3:
ERROR: duplicate key value violates unique constraint "title_unique"
DETAIL: Key (title)=(mytitle) already exists.
Or, using PHP:
["errorInfo"]=>
array(3) {
[0]=>
string(5) "23505"
[1]=>
int(7)
[2]=>
string(117) "ERROR: duplicate key value violates unique constraint "title_unique"
DETAIL: Key (title)=(mytitle) already exists."
}
According to the paragraph from the PostgreSQL documentation, shouldn’t the constraint name title_unique
be found in a separate field of the error info?
I’m using PostgreSQL 9.4.5.