Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm sorry for being a SQL noob. Can you elaborate on what is wrong with this, and what would be the way to write it without causing the scale of problem described in the OP?


The problem is that the condition is parsed as

  (user=671156 AND permission=16 AND org=101) OR 102
The right way is to use something like

  org IN (101, 102)


There are lots of good answers already posted, but if I can make a further suggestion...

It is often worth running a SELECT on the WHERE clause you are about to use for your UPDATE. That way you can make sure only a limited amount of data comes back before you launch something catastrophic.


the last OR statement "OR 102" will evaluate true.

It should be

    UPDATE permissions SET allow = 1 WHERE user=671156 AND permission=16 AND org=101 OR org=102;


You and fazzone have posted different answers. I'm a little unclear on which matches the original intent, but your where clause is equivalent to:

  (user=671156 AND permission=16 AND org=101) OR (org=102)


That is still wrong and would apply to everyone in org 102


Applying to everyone in org 102 is the intended behavior no? The slip-up would be the 'OR 102' which would just evaluate to true.


The example query is supposed to match a single account, not an org.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: