Why is ON CONFLICT DO UPDATE not working with PostgreSQL column aliasing? - Stack Overflow

I'm trying to perform an INSERT operation with an ON CONFLICT DO UPDATE clause in PostgreSQL. My t

I'm trying to perform an INSERT operation with an ON CONFLICT DO UPDATE clause in PostgreSQL. My table contains column names with aliases (e.g., "ITEM_CODE(material_code)"), and I want to update the corresponding fields when a conflict occurs on "ITEM_CODE(material_code)". Here's the SQL query I'm using:

INSERT INTO api_itemmaster (
    "ITEM_CODE(material_code)",
    "ITEM_NAME(material_name)",
    "ITEM_GROUP_CODE",
    "UNIT(base_unit)",
    "PACK(pack_size)",
    "ITEM_CLASS_CODE(material_type)",
    "DIVISION_CODE(division)",
    "SEGMENT_CODE",
    "CAT_CODE",
    "ACTIVE",
    "FORMT",
    created_on,
    updated_on,
    active_state
) VALUES (
    '5000',
    'OSKAR',
    '225',
    'STR',
    '15',
    'ZF',
    '8000',
    '30000',
    '004',
    '1',
    '20',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP,
    false
) ON CONFLICT ("ITEM_CODE(material_code)") 
DO UPDATE SET
    "ITEM_NAME(material_name)" = EXCLUDED."ITEM_NAME(material_name)",
    "ITEM_GROUP_CODE" = EXCLUDED."ITEM_GROUP_CODE",
    "UNIT(base_unit)" = EXCLUDED."UNIT(base_unit)",
    "PACK(pack_size)" = EXCLUDED."PACK(pack_size)",
    "ITEM_CLASS_CODE(material_type)" = EXCLUDED."ITEM_CLASS_CODE(material_type)",
    "DIVISION_CODE(division)" = EXCLUDED."DIVISION_CODE(division)",
    "SEGMENT_CODE" = EXCLUDED."SEGMENT_CODE",
    "CAT_CODE" = EXCLUDED."CAT_CODE",
    "ACTIVE" = EXCLUDED."ACTIVE",
    "FORMT" = EXCLUDED."FORMT",
    updated_on = EXCLUDED.updated_on;

However, the ON CONFLICT DO UPDATE clause doesn't seem to work, and no updates are applied to the existing row.

Ensured that the table and column names are correct. Verified that the ITEM_CODE(material_code) constraint is unique in the table. Confirmed that the syntax aligns with PostgreSQL's ON CONFLICT documentation.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745577169a4634035.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信