What Samir suggested is implemented (more or less) in jOOQ-meta. You could
use that, but it has quite an overhead: That of caching the entire schema
in memory. And the cache is not thread safe.

Another option would be to use DSLContext.meta() to query the dictionary
views via JDBC's DatabaseMetaData (or use the latter directly).

By the way

I'm a bit annoyed by the extra exception (and stack compilation), for the
> performance cost, but I haven't found any better way.


I wouldn't worry about the stack compilation too much in the event of a
database query. Even the latency produced by the TCP/IP connection is very
likely to outshine any exception cost in Java :)

Besides that, jOOQ-meta also does this internally, e.g. to see if it runs
on Oracle 12, 11, or 10. It just checks if a column is available from a
dictionary view by selecting it. On error: Not available.

Hope this helps,
Lukas

2016-05-26 23:40 GMT+02:00 Samir Faci <[email protected]>:

> That's fairly DB specific.
>
> For postgres for example you can do something along these lines:
>
> source:
> http://stackoverflow.com/questions/20582500/how-to-check-if-a-table-exists-in-a-given-schema
>
>
>
> SELECT EXISTS (
>    SELECT 1
>    FROM   information_schema.tables
>    WHERE  table_schema = 'ui'
>    AND    table_name = 'users');
>
> which returns a boolean of true if it exists.  Each DB will have a at least 
> one way of doing this but it's hardly consistent.
>
> MySQL has a different set of tables to check etc...You can find the correct 
> tables to query and invoke it via Jooq if you'd like.
>
>
>
>
> On Thu, May 26, 2016 at 2:11 PM, <[email protected]> wrote:
>
>> Hi
>>
>> I would like to figure out if a table is existing.
>>
>> I haven't found a cross database way to do it up to now.
>>
>> As such I'm seriously thinking of throwing some stupid select at it and
>> see whether it fails. I'm a bit annoyed by the extra exception (and stack
>> compilation), for the performance cost, but I haven't found any better way.
>>
>> Am I missing some better way?
>>
>> Thanks again for jOOQ!
>>
>> NB: I know of createTableIfNotExists, but this isn't on all DB...
>>
>> cheers
>> joseph
>>
>> --
>> 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 [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Thank you
> Samir Faci
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to