postgresql - SQL update in one statement instead of two -



postgresql - SQL update in one statement instead of two -

is possible next in 1 statement instead of 2. need set isactive flag 1 id , set others false. im using postgres db.

tblnames ------------------------ id,name,isactive 1,'n1',true 2,'n2',false 3,'n3',false 4,'n4',false update tblnames set isactive = true id = 4 update tblnames set isactive = false id != 4

does work?

update tblnames set isactive = (id = 4)

in case doesn't (i don't know postgres syntax enough), certainly work:

update tblnames set isactive case id when 4 true else false end

sql postgresql

Comments

Popular posts from this blog

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -