Skip to content

Wrong SQL syntax generated for empty inserts of fetched records without any touched values #17708

Closed
@Hellblazer

Description

Expected behavior

When inserting a record that uses the JOOQ record versioning, the generated SQL should not contain the key words "default values"

Actual behavior

I am upgrading an ancient project from quite a while ago and running into trouble now that I'm updating JOOQ, etc. The issue is that I selected a record from a table, and then reinsert that to bump the version. This fails because the generated Postgres SQL contains "default values", while clearly adding the "version" column.

Here's what I'm doing:

        ExistentialRecord existential = create.selectFrom(EXISTENTIAL)
                                              .where(EXISTENTIAL.ID.equal(wko.id()))
                                              .fetchOne();
        existential.insert();

Here's the stack trace:

org.jooq.exception.DataAccessException: SQL [insert into "ruleform"."existential" ("version") default values returning "ruleform"."existential"."id"]; ERROR: syntax error at or near "default"
  Position: 50
  
	at org.jooq_3.19.15.POSTGRES.debug(Unknown Source)
	at org.jooq.impl.Tools.translate(Tools.java:3641)
	at org.jooq.impl.Tools.translate(Tools.java:3629)
	at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:827)
	at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:362)
	at org.jooq.impl.TableRecordImpl.storeInsert0(TableRecordImpl.java:207)
	at org.jooq.impl.TableRecordImpl.lambda$storeInsert$0(TableRecordImpl.java:172)
	at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:144)
	at org.jooq.impl.TableRecordImpl.storeInsert(TableRecordImpl.java:171)
	at org.jooq.impl.TableRecordImpl.insert(TableRecordImpl.java:159)
	at org.jooq.impl.TableRecordImpl.insert(TableRecordImpl.java:154)
	at com.chiralbehaviors.CoRE.kernel.Bootstrap.populate(Bootstrap.java:167)
	at com.chiralbehaviors.CoRE.kernel.Bootstrap.populateAgencies(Bootstrap.java:175)
	at com.chiralbehaviors.CoRE.kernel.Bootstrap.constructKernelWorkspace(Bootstrap.java:110)
	at com.chiralbehaviors.CoRE.kernel.Bootstrap.bootstrap(Bootstrap.java:101)
	at com.chiralbehaviors.CoRE.kernel.Bootstrap.boostrap(Bootstrap.java:57)
	at com.chiralbehaviors.CoRE.kernel.BootstrapTest.testBootstrap(BootstrapTest.java:36)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "default"
  Position: 50
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2733)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2420)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:372)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:517)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:434)
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:194)
	at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:137)
	at org.jooq.tools.jdbc.DefaultPreparedStatement.executeQuery(DefaultPreparedStatement.java:104)
	at org.jooq.impl.AbstractDMLQuery.executeReturningQuery(AbstractDMLQuery.java:1382)
	at org.jooq.impl.AbstractDMLQuery.execute(AbstractDMLQuery.java:1213)
	at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:348)
	... 39 more

Steps to reproduce the problem

Create a table that uses versioning. Insert some records into it. Select one of those records subsequently and reinsert using the record.insert()

jOOQ Version

JOOQ open source version 3.19.15

Database product and version

PostgreSQL 17

Java Version

GraalVM 23

JDBC / R2DBC driver name and version (include name if unofficial driver)

org.postgresql:postgresql:42.7.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions