Using any() has the disadvantage that in JDBC it is necessaryto create
an array with connection.createArrayOf() and indicatethe type of the
array, which complicates automation.
With statement.setObject() you can pass any type of parameter.JDBC
could add a method that doesn't need the array type.
String sql = "select author from article where id = any(?)";
try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setArray(1,
connection.createArrayOf("varchar", new String[] {"home",
"system"}));}
VS
query("select author from article where id = any(?)", new String[]
{"home", "system"});
El lun, 01-03-2021 a las 17:21 +0100, Pavel Stehule escribió:
> po 1. 3. 2021 v 17:15 odesílatel Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com> napsal:
> > po 1. 3. 2021 v 17:08 odesílatel Alejandro Sánchez <
> > alex(at)nexttypes(dot)com> napsal:
> > > The benefit is ease of use. One of the great advantages of
> > > prepared statements is nothaving to concatenate strings. The use
> > > of arrays would also be very useful.
> > > query("select " + column1 + "," + column2 from " " + table + "
> > > where id in (?), ids);
>
> The argument with arrays is not good. You can work with arrays just
> on binary level, that is more effective. But just you should use
> operator = ANY() instead IN.
>
> Regards
> Pavel