coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.06k stars 1.37k forks source link

bulk update uuid PostgreSQL #2916

Closed DGDarkKing closed 1 month ago

DGDarkKing commented 1 month ago

Hello! When try bulk update uuid field then peewee generate next SQL (PostgreSQL 15.0)

_taskid and _"video_forprocessing"."id" are UUID

UPDATE "video_for_processing" 
SET "task_id" = CASE "video_for_processing"."id" 
                    WHEN '7ce80e1f6318489c9bfff95277085cc9' THEN 'c6e12b50128e492095529b31d4132248' 
                    WHEN 'c653225430fb4de28ef7b6901ee0253d' THEN '1f9998836f2047799d8081427a5b4cf1'
                    WHEN 'ff3ef6a1fc9e418f97556af4f238724f' THEN 'a6b427c97aa341a4b09bf22bb6e1de70'
                END
    WHERE ("video_for_pro

PostgreSQL throws exception:

ERROR: column "task_id" is of type uuid but expression is of type text

If wrap case statement to uuid(CASE ...) then it executes successfully

Example:

UPDATE "video_for_processing" 
SET "task_id" = uuid(CASE "video_for_processing"."id" 
                    WHEN '7ce80e1f6318489c9bfff95277085cc9' THEN 'c6e12b50128e492095529b31d4132248' 
                    WHEN 'c653225430fb4de28ef7b6901ee0253d' THEN '1f9998836f2047799d8081427a5b4cf1'
                    WHEN 'ff3ef6a1fc9e418f97556af4f238724f' THEN 'a6b427c97aa341a4b09bf22bb6e1de70'
                END)
    WHERE ("video_for_processing"."id" IN ('7ce80e1f6318489c9bfff95277085cc9', 'c653225430fb4de28ef7b6901ee0253d', 'ff3ef6a1fc9e418f97556af4f238724f'))
coleifer commented 1 month ago

Unfortunately, Postgres has this issue with certain types of expressions. This is a known issue:

Suggestions remain the same: