I am using Postgres 9.5 on CentOS 6. I have the following table (DDL).
CREATE TABLE core_table.user_list(
user_id SMALLSERIAL DEFAULT nextval('core_table.user_list_user_id_seq'::regclass) NOT NULL,
user_name VARCHAR(50) NOT NULL,
full_name VARCHAR(255),
role_id INTEGER DEFAULT 1,
is_accessible INTEGER DEFAULT 1,
remarks VARCHAR(255),
password VARCHAR(50),
customer_schema VARCHAR(50),
core_schema VARCHAR(50),
CONSTRAINT user_list_pkey PRIMARY KEY(user_id, user_name),
CONSTRAINT user_list_user_id_key UNIQUE(user_id)
)
WITH (oids = false);
with 4 existing rows of data.
Row 1:
user_id: 1
user_name: kelly
full_name: kelly petz
role_id: 1
is_accessible: 1
remarks: <null>
password: test123
customer_schema: kelly_db1
core_schema: kelly_db1
Row 2:
user_id: 2
user_name: kelly
full_name: kelly petz
role_id: 1
is_accessible: 1
remarks: <null>
password: test123
customer_schema: petz_db1
core_schema: kelly_db1
Row 3:
user_id: 3
user_name: sam
full_name: sam howiz
role_id: 1
is_accessible: 1
remarks: <null>
password: test456
customer_schema: kelly_db1
core_schema: kelly_db1
Row 4:
user_id: 4
user_name: jon
full_name: jon lam
role_id: 1
is_accessible: 1
remarks: <null>
password: test789
customer_schema: lam_db1
core_schema: lam_db1
I hit an error when I tried to do the following UPSERT.
INSERT INTO core_table.user_list
(user_name, full_name, remarks, password, customer_schema, core_schema, role_id, is_accessible)
VALUES
('kelly', 'kelly petz', 'The Boss', 'test123', 'snoppy_db1', 'snoppy_db1', 1, 1)
ON CONFLICT (user_name)
DO UPDATE SET
password = 'test123',
remarks = 'The Boss';
The error is "ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification".
Can someone please point out my error for me and how to resolve it?