Re: Invoking a function within a batch statement

From: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>
To: Evan Meagher <evan(dot)meagher(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org, stevenschlansker(at)gmail(dot)com
Subject: Re: Invoking a function within a batch statement
Date: 2016-08-19 15:00:34
Message-ID: CAB=Je-HwpBLUU1RA48J-h04WbGqEHxXNswi+fzPmWQd-Rf-Yow@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Evan>However, because Postgres functions are invoked using SELECT, they
return a table-like result, so even though my PL/pgSQL function returns
VOID, the queries fail in the JDBC driver because it's expecting a null
result.

Evan,

Can you please try the latest pgjdbc 9.4.1210-SNAPSHOT + @GetGeneratedKeys
near your @SqlBatch("select ...") kind of statement?

The idea is as follows:
1) jDBI would issue prepareStatement(..., Statement.RETURN_GENERATED_KEYS);
2) pgjdbc has recently learned to handle "return generated keys" better, so
that "return_generated_keys" would hint pgjdbc that it should expect some
response (including empty rowset), so it won't fail with "none was
expected".

Technically speaking, the question "if pgjdbc should fail when unexpected
row data comes in a response to a query" was raised (see
https://github.com/pgjdbc/pgjdbc/issues/488#issuecomment-237908650 ),
however historical behavior was just fail with "A result was returned when
none was expected"

The solution is to use proper API when executing statements that return
something. For instance: executeQuery, or use "generated keys" API.

Vladimir

>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message rapidtransit440 2016-08-21 23:45:19 Anyone Getting deadlocks using 9.5
Previous Message Dave Cramer 2016-08-19 13:03:23 Re: Invoking a function within a batch statement