Closed ShajeeOnCloud closed 2 years ago
Post a minimal example reproducing the issue.
ok after doing some debugging and investigation I found the issue, it is because of updating sequences in postgres, or rather how the sequences are getting updated SELECT SETVAL('table1_id_seq', COALESCE(MAX(id), 1) ) FROM table1;
using SETVAL is a legitimate way of updating sequences in Postgres apart from the Alter statement, howeever from DbSetup a executeUpdate is fired for all SQLs. Making the above execution fail and resulting in stacktrace as I pasted above.
is it possible to execute a SELECT query from DbSetup?
DbSetup is designed to setup your database before tests. So its goal is rather to delete and create stuff in the database than to select stuff from the database. I can understand why you'd want to use a select here, so I see two solutions:
alter sequence restart with
, as described here: https://www.postgresql.org/docs/current/sql-altersequence.htmlThank you for the response and the possible alternatives. Option 1 might not work as I need reference to the last/max sequence in a given table. I guess Option 2 it is then.
Hi,
I am using DBSetup for running test cases. It works fine with Oracle and H2. Recently there is a move to Postgres. Some of the queries are returning below error
Caused by: org.postgresql.util.PSQLException: A result was returned when none was expected. at org.postgresql.jdbc.PgStatement.checkNoResultUpdate(PgStatement.java:276) at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:266) at com.zaxxer.hikari.pool.ProxyStatement.executeUpdate(ProxyStatement.java:119) at com.zaxxer.hikari.pool.HikariProxyStatement.executeUpdate(HikariProxyStatement.java) at com.ninja_squad.dbsetup.operation.SqlOperation.execute(SqlOperation.java:64) at com.ninja_squad.dbsetup.operation.CompositeOperation.execute(CompositeOperation.java:92) at com.ninja_squad.dbsetup.operation.CompositeOperation.execute(CompositeOperation.java:92) at com.ninja_squad.dbsetup.DbSetup.launch(DbSetup.java:107)
Debugging into the stack trace the error is caused when executing a set of sql statements.
Environment (from build.gradle):
testImplementation group: 'com.ninja-squad', name: 'DbSetup', version: '2.1.0' testImplementation group: 'org.postgresql', name: 'postgresql', version: '42.3.6'
I have SQLs that I am passing to DBSetup for execution. First goes a set of delete statements and then insert statements.
Can someone please give some inputs on how to solve this issue?