micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

Query with RETURNING statement crashes due to using executeUpdate instead of execute

Open Dattish opened this issue 3 years ago • 1 comments

Expected Behavior

The query should return the updated rows.

This seems to have been fixed a long time ago but might have broken at some point since.

Actual Behaviour

Crashes with Error executing SQL UPDATE: A result was returned when none was expected

Steps To Reproduce

  1. Create a db and a table.
  2. Create a repository with a method with the following kind of query @Query(value = "update ... where ... returning *", readOnly = false)
  3. Insert some data
  4. Call the method

Environment Information

OS: macOS Monterey 12.4, Windows 10 19044.1706 JDK: OpenJDK 17+35-2724

Example Application

https://github.com/Dattish/micronaut-data-repro

Version

3.5.1

Dattish avatar Jun 10 '22 07:06 Dattish

The referenced issue has a simple query so it works but the update is a different thing. We would need to add a bit different API to support this kind of return.

dstepanov avatar Jun 10 '22 07:06 dstepanov

I am also running into this issue. Any status update on this?

Discordia avatar May 05 '23 08:05 Discordia

Hi, we are also running into this issue. This has been open for more than a year! Any updates or workarounds would be helpful. Thanks!

VishGov avatar Sep 11 '23 15:09 VishGov

Same here, it's still not fixed

pixnbit avatar Sep 27 '23 07:09 pixnbit

If you are using the 3.x releases and want to workaround this issue, you can do the following query instead:

WITH realQuery AS (
  UPDATE/INSERT/DELETE ..
  RETURNING ...
)
SELECT ... FROM realQuery
...

You'll need to mark the method @Transactional and you can even do extra operations, such as aggregation, in the select, that are not allowed with RETURNING.

RonBarkan avatar Mar 13 '24 03:03 RonBarkan