POSTGRESQL: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
POSTGRESQL: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
我正在尝试使用以下查询对名为 "message_payload" 的 table 执行更新插入操作,但出现错误:
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
SQL state: 42P10
查询:
INSERT INTO public.error_message(
id, created_by, created_dt, modified_by, modified_dt, attempt, message_headers,
message_main_topic, message_payload, message_status, message_status_code)
VALUES (51, null, null, null, null, 1, '{
"jsonContent": {
"content-length": "1635",
"message_status_code": "417",
"cookie": "JSESSIONID=279AF4C174E6192BDAB11A067768BBD5",
"postman-token": "f0f33e86-498f-452a-aaf6-18eb84dc5907",
"kafka_timestampType": "CREATE_TIME",
"message_id": "21",
"kafka_receivedMessageKey": "null",
"kafka_receivedTopic": "error-topic",
"accept": "*/*",
"kafka_offset": "33",
"kafka_consumer": "org.apache.kafka.clients.consumer.KafkaConsumer@5091bb5f",
"host": "localhost:8082",
"content-type": "application/json",
"connection": "keep-alive",
"cache-control": "no-cache",
"kafka_receivedPartitionId": "0",
"kafka_receivedTimestamp": "1552305428711",
"accept-encoding": "gzip, deflate",
"message_main_topic": "ldarsQCustomStatistics.1",
"user-agent": "PostmanRuntime/7.6.1"
}
}', 'ldarsQCustomStatistics.1', '{
"jsonContent": {
"messageTime": 16772223422,
"messageRev": 9,
"businessId": "DB",
"messageId": "55"
}
}', 1, 201)
ON CONFLICT ((message_payload->'jsonContent'->>'message_id'))
DO UPDATE SET attempt = error_message.attempt + 1, message_headers = EXCLUDED.message_headers,
message_status_code = EXCLUDED.message_status_code, message_status = EXCLUDED.message_status,
created_by = EXCLUDED.created_by, created_dt = EXCLUDED.created_dt,
modified_by = EXCLUDED.modified_by, modified_dt = EXCLUDED.modified_dt,
message_main_topic = EXCLUDED.message_main_topic, message_payload = EXCLUDED.message_payload,
id = DEFAULT
您很可能缺少对该特定字段的唯一约束。
示例:
CREATE UNIQUE INDEX j_msgid_idx ON public.error_message((data->'jsonContent'->>'message_id'));
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification SQL state: 42P10
查询:
INSERT INTO public.error_message(
id, created_by, created_dt, modified_by, modified_dt, attempt, message_headers,
message_main_topic, message_payload, message_status, message_status_code)
VALUES (51, null, null, null, null, 1, '{
"jsonContent": {
"content-length": "1635",
"message_status_code": "417",
"cookie": "JSESSIONID=279AF4C174E6192BDAB11A067768BBD5",
"postman-token": "f0f33e86-498f-452a-aaf6-18eb84dc5907",
"kafka_timestampType": "CREATE_TIME",
"message_id": "21",
"kafka_receivedMessageKey": "null",
"kafka_receivedTopic": "error-topic",
"accept": "*/*",
"kafka_offset": "33",
"kafka_consumer": "org.apache.kafka.clients.consumer.KafkaConsumer@5091bb5f",
"host": "localhost:8082",
"content-type": "application/json",
"connection": "keep-alive",
"cache-control": "no-cache",
"kafka_receivedPartitionId": "0",
"kafka_receivedTimestamp": "1552305428711",
"accept-encoding": "gzip, deflate",
"message_main_topic": "ldarsQCustomStatistics.1",
"user-agent": "PostmanRuntime/7.6.1"
}
}', 'ldarsQCustomStatistics.1', '{
"jsonContent": {
"messageTime": 16772223422,
"messageRev": 9,
"businessId": "DB",
"messageId": "55"
}
}', 1, 201)
ON CONFLICT ((message_payload->'jsonContent'->>'message_id'))
DO UPDATE SET attempt = error_message.attempt + 1, message_headers = EXCLUDED.message_headers,
message_status_code = EXCLUDED.message_status_code, message_status = EXCLUDED.message_status,
created_by = EXCLUDED.created_by, created_dt = EXCLUDED.created_dt,
modified_by = EXCLUDED.modified_by, modified_dt = EXCLUDED.modified_dt,
message_main_topic = EXCLUDED.message_main_topic, message_payload = EXCLUDED.message_payload,
id = DEFAULT
您很可能缺少对该特定字段的唯一约束。
示例:
CREATE UNIQUE INDEX j_msgid_idx ON public.error_message((data->'jsonContent'->>'message_id'));