2

I am trying to create a database from a Java application running in Micronaut framework using jOOQ.

The code

contextSupplier.get().createDatabaseIfNotExists(this.databaseName).execute();

with a PostgreSQL datasource fails with:

org.jooq.exception.DataAccessException: SQL [do $$ begin create database "mydb"; exception when sqlstate '42P07' then null; end $$]; ERROR: CREATE DATABASE cannot run inside a transaction block

Is there a simple way to turn transactions off within jOOQ just for this statement?

2
  • Why does it run inside a transaction? Can you please show your code? Commented Mar 2, 2021 at 10:44
  • @SimonMartinelli, that basically IS the entire code. I do not touch any transactional behavior other than what jOOQ does out of the box. Commented Mar 2, 2021 at 15:50

1 Answer 1

2

As of jOOQ 3.14, the DSLContext.createDatabaseIfNotExists() method is supported by these dialects (see its @Support annotation):

@Support({AURORA_POSTGRES,COCKROACHDB,MARIADB,MEMSQL,MYSQL,SQLDATAWAREHOUSE,SQLSERVER})

So, this statement is not yet supported in jOOQ for PostgreSQL - if I remember correctly, for this precise reason. Perhaps there's a different way to emulate the statement, but it hasn't been implemented yet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.