You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bind parameters can use the form of ?1, ?2, ?3 ... for binding collection parameters that we want to get expanded into multiple bind values.
Note that when we use databases that support binding Array types such as Postgres we could tend to use that (e.g. Postgres ANY).
This is more useful when we are not using such a database and want to bind an in clause with a list/collection of bind values.
Example
DB.sqlUpdate("delete from o_customer where id in (?1)")
.setParameter(1, asList(9991, 9992, 9993))
.execute();
// translates to:
deletefrom o_customer where id in (?,?,?); -- bind(9991, 9992, 9993)
We only use the position suffix for the parameters that we want to expand. For the example below we only use ? for the first parameter as we don't want that expanded. We use ?2 for the parameter we want expanded.
DB.sqlUpdate("delete from o_customer where status = ? and id in (?2)")
.setParameter(1, "NEW")
.setParameter(2, asList(9991, 9992, 9993))
.execute();
deletefrom o_customer where status = ? and id in (?,?,?); -- bind("NEW", 9991, 9992, 9993)
We can also use setParams() with bind parameters set using varargs.
DB.sqlUpdate("delete from o_customer where status = ? and id in (?2)")
.setParams( "NEW", asList(9991, 9992, 9993))
.execute();
The text was updated successfully, but these errors were encountered:
Bind parameters can use the form of
?1
,?2
,?3
... for binding collection parameters that we want to get expanded into multiple bind values.Note that when we use databases that support binding
Array
types such as Postgres we could tend to use that (e.g.Postgres ANY
).This is more useful when we are not using such a database and want to bind an
in clause
with a list/collection of bind values.Example
We only use the position suffix for the parameters that we want to expand. For the example below we only use
?
for the first parameter as we don't want that expanded. We use?2
for the parameter we want expanded.We can also use
setParams()
with bind parameters set using varargs.The text was updated successfully, but these errors were encountered: