How to define the schema when creating table ?

22 views
Skip to first unread message

joseph...@gmail.com

unread,
Jun 9, 2016, 4:59:26 PM6/9/16
to jOOQ User Group
Hi

I tried various ways to define a schema when creating table but I don't manage to get it work.

For example, when writing :
val dsl: DSLContext = using(dataSource, dialect, new Settings().withRenderMapping(new RenderMapping().withDefaultSchema("SCHEMA_NAME")))
dsl.createTableIfNotExists("FOO").columns(...).execute()

But after in the logs I see: create table if not exists "FOO" (..) => the schema is missing

When I try to query it through the table template approach (cf // https://stackoverflow.com/questions/35154523/jooq-table-template-dynamic-table-name-for-queries), it then fails because the template rightly prefix the table name by the schema...

What am I missing ?

Thanks in advance

Best,
joseph

Lukas Eder

unread,
Jun 10, 2016, 2:27:26 AM6/10/16
to jooq...@googlegroups.com
Hi Joseph,

Thank you very much for your enquiry. I quickly checked and noticed that RenderMapping is currently not applied for table(Name) calls, so the rendermapping approach won't work for you here. This is a bug. I've registered an issue for this:

But you don't need mapping in your case. Notice how the createTable[IfNotExists]() method is overloaded and also accepts a Name or a Table argument. You can construct org.jooq.Name references using DSL.name():

They model qualified names. E.g. DSL.name("SCHEMA_NAME", "TABLE_NAME"). You can pass that directly to the CREATE TABLE statement, or wrap it explicitly in a table via DSL.table(Name), e.g. table(name("SCHEMA_NAME", "TABLE_NAME")).

Hope this helps.
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

joseph...@gmail.com

unread,
Jun 10, 2016, 3:49:49 AM6/10/16
to jOOQ User Group
Hi Lukas

Sure it helps, thanks a lot =)

++
joseph
Reply all
Reply to author
Forward
0 new messages