Home > Software engineering >  Update record with clause IN
Update record with clause IN

Time:09-28

I'm using Grails 4.0.12, and I'm trying to make an update using IN clause, this is my simple code:

def rowId="100,101"
Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (:ids)", [ids: rowId])

If I build the query string like this, everything works:

 Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (" ids ")")

While in the fist example I'm getting this error:

java.lang.String cannot be cast to java.lang.Long

Which seems reasonable if I pass just one Id without IN clause.

CodePudding user response:

Try to correct your first example in the following way:

def rowIds = [100, 101]
Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (:ids)", [ids: rowIds])
  • Related