Re: Improvements in prepared statements

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

po 1. 3. 2021 v 21:35 odesílatel Alejandro Sánchez <alex(at)nexttypes(dot)com>
napsal:

> Using any() has the disadvantage that in JDBC it is necessary
>
> to create an array with connection.createArrayOf() and indicate
>
> the 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"});
>

Can be, but this is a client side issue. It is about design of client side
API.

Pavel

> 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. O
>
> ne of the great advantages of prepared statements is not
>
> having 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

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2021-03-01 21:05:41 Why does the BF sometimes not dump regression.diffs?
Previous Message Mark Dilger 2021-03-01 21:05:03 Re: [PATCH] Improve amcheck to also check UNIQUE constraint in btree index.