gpt4 book ai didi

POSTGRESQL:错误:没有与 ON CONFLICT 规范匹配的唯一或排除约束

转载 作者:行者123 更新时间:2023-11-29 12:40:03 26 4
gpt4 key购买 nike

enter image description here我正在尝试使用以下查询对名为“message_payload”的表执行更新插入操作,但出现错误:

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'));

关于POSTGRESQL:错误:没有与 ON CONFLICT 规范匹配的唯一或排除约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55134989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com