You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to Jooq and CTE's to do a 'move' operation as described here
I can delete rows from one table and insert those rows into another table in the one operation.
Actual behavior
I'm getting a null pointer exception
java.lang.NullPointerException
at org.jooq.impl.DefaultExecuteContext.(DefaultExecuteContext.java:311)
at org.jooq.impl.DefaultExecuteContext.(DefaultExecuteContext.java:299)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:263)
at org.jooq.impl.AbstractDelegatingQuery.execute(AbstractDelegatingQuery.java:111)
val create =DSL.using(config)
create.insertInto(Tables.TMP1).values("ONE").execute()
create.insertInto(Tables.TMP1).values("TWO").execute()
//the delete statement I want to put in my cteval deleteResultStep = create.delete(TMP1).returningResult(TMP1.NAME)
println(deleteResultStep.getSQL(ParamType.INLINED))
//when running delete by itself it works
deleteResultStep.fetch().forEach {
//this prints the 2 rows returned from the deleteprintln(it)
}
//add the rows back into table
create.insertInto(Tables.TMP1).values("ONE").execute()
create.insertInto(Tables.TMP1).values("TWO").execute()
//now put the same statement into a cteval deleteCte =DSL.name("a").fields("name").`as`(deleteResultStep)
//use cte to move data from tmp1 to tmp2val move =DSL.with(deleteCte).insertInto(Tables.TMP2).columns(Tables.TMP2.NAME)
.select(create.select(deleteCte.field("name", Tables.TMP1.NAME.dataType)).from(deleteCte))
//this sql is missing the returning clause that was present when executed standaloneprintln(move.getSQL(ParamType.INLINED))
//npe hereval execute = move.execute()
println(execute)
When I print out the deleteResultStep above I get:
Ah, I get it. The NPE is obviously confusing. I can reproduce it, though I get a different stack trace on jOOQ 3.17. Instead, a DetachedException should be thrown.
You're doing:
val move =DSL.with(deleteCte)
When you should be doing:
val move = create.with(deleteCte)
Your CTE query isn't attached to your configuration.
lukaseder
changed the title
CTE with delete returning causes NPE
NullPointerException thrown instead of DetachedException, when executing detached query
Aug 29, 2022
Expected behavior
I'm trying to Jooq and CTE's to do a 'move' operation as described here
I can delete rows from one table and insert those rows into another table in the one operation.
Actual behavior
I'm getting a null pointer exception
Steps to reproduce the problem
Create two tables
Run jooq code generation
Test kotlin code:
When I print out the deleteResultStep above I get:
note the 'returning' clause.
Now when I println out the deleteCte above I get:
note the returning clause has gone missing.
executing that statement returns:
I change this to
It executes correctly and data is moved from table 1 to 2.
jOOQ Version
Community Edition 3.15.1
Database product and version
PostgreSQL 14.2 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 10.3.1_git20211027) 10.3.1 20211027, 64-bit
Java Version
openjdk version "11.0.13" 2021-10-19 LTS OpenJDK Runtime Environment Zulu11.52+13-CA (build 11.0.13+8-LTS) OpenJDK 64-Bit Server VM Zulu11.52+13-CA (build 11.0.13+8-LTS, mixed mode)
OS Version
MacOS, uname: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
JDBC driver name and version (include name if unofficial driver)
org.postgresql:postgresql:42.4.0
The text was updated successfully, but these errors were encountered: