Casting NULL type when updating multiple rows

前端 未结 3 1896
醉话见心
醉话见心 2020-11-29 09:38

I have a problem when I try to update many rows at the same time.

Here is the table and query I use (simplified for better reading):

table<

3条回答
  •  遥遥无期
    2020-11-29 10:20

    If you have a script generating the query you could extract and cache the data type of each column an create the type cast accordingly. E.g:

    SELECT column_name,data_type,udt_name 
    FROM information_schema.columns 
    WHERE table_name = 'foo';
    

    From this udt_name you'll get the necessary cast as you explained in the last paragraph. Additionally you could do this:

    UPDATE foo
    SET x = t.x
    FROM (VALUES(null::int4,756),(null::int4,6300))
    AS t(x,pkid)
    WHERE foo.pkid = t.pkid;
    

提交回复
热议问题