Re: Improvements in prepared statements

From: Alejandro Sánchez <alex(at)nexttypes(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Improvements in prepared statements
Date: 2021-03-01 20:35:02
Message-ID: 988b92e685a47e3fc4b96bfe38c7d9f4fba98582.camel@nexttypes.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2021-03-01 20:40:27 Re: [PoC] Non-volatile WAL buffer
Previous Message Tom Lane 2021-03-01 20:23:24 Re: [PATCH] Improve amcheck to also check UNIQUE constraint in btree index.