Cast table name to OID using jooq

Viewed 105

I need to cast a table name to object identifier using JOOQ. In plain SQL I would do:

'my_table'::regclass::oid

I couldn't find a DataType for casting the value (It exists a PostgresDataType.OID, but not a PostgresDataType.REGCLASS or something similar, also using PostgresDataType directly is deprecated).

I also played with DSL.inline, DSL.val, but can't obtain the desired output.

UPDATE

I realized there's a PostgresDSL.oid that returns Field<Long> and produces following output "my_table".oid, but I don't have a reference for the table (I have the table name as text), so it's not valid for my use case.


Is there a way to cast a table name to Postgres Object Identifier (OID) throught JOOQ?

1 Answers

After some time testing I found a working solution (Not sure the best).

DSL.field("{0}::regclass::oid", DSL.inline(name))

This way we create a "field" with all the castings needed hardcoded and set the value as a binding.

Related