如何更新 postgresql 中的行以忽略错误?
How do I update row in postgessql to ignore error?
我试图在 postgres 中更新我的 table 中的数千行,但我收到一个用户不存在的错误,因此我的 table 没有更新。
如何更新 table 中的行以忽略用户 table
中不存在用户的任何错误
UPDATE table
SET userid =1, WHERE app = 'aaa'
SET userid =2, WHERE app = 'bbb'
SET userid =3, WHERE app = 'aaa'
SET userid =4, WHERE app = 'ccc'
SET userid =5, WHERE app = 'aaa'
SET userid =6, WHERE app = 'bbb'
如果例如 userid=3 不存在,我该如何忽略任何错误并更新我的行。
谢谢
我会用 values()
:
update t
set userid = v.userid
from (values ('aaa', 1), ('bbb', 2), . . .
) v(app, userid)
where v.app = t.app;
我试图在 postgres 中更新我的 table 中的数千行,但我收到一个用户不存在的错误,因此我的 table 没有更新。 如何更新 table 中的行以忽略用户 table
中不存在用户的任何错误UPDATE table
SET userid =1, WHERE app = 'aaa'
SET userid =2, WHERE app = 'bbb'
SET userid =3, WHERE app = 'aaa'
SET userid =4, WHERE app = 'ccc'
SET userid =5, WHERE app = 'aaa'
SET userid =6, WHERE app = 'bbb'
如果例如 userid=3 不存在,我该如何忽略任何错误并更新我的行。 谢谢
我会用 values()
:
update t
set userid = v.userid
from (values ('aaa', 1), ('bbb', 2), . . .
) v(app, userid)
where v.app = t.app;