Hi all,
I had the following code which wasn't rendered like I expected. The
added CAST was missing fromt he rendered SQL, but important in my
case. Reason is that Postgres has a result type of "double precision",
which really needs to be casted to an integer in my case.
> DSL.field
> (
> "extract(epoch FROM now() - {0})",
> SQLDataType.INTEGER,
> CLTS.COL_PACKET_WHEN
> ).div(3600).div(24).cast(SQLDataType.INTEGER)
This resulted in the following SQL:
> ((extract(epoch FROM now() - "clts"."packet_when") / 3600) / 24)
The field was of type "Integer" and the results of "div" were so as
well. Might that have been the problem, that jOOQ decided the cast
wasn't actually necessary and didn't render it?
My current implementation looks like the following and renders the
cast:
> Field<Integer> secsCalc = DSL.field
> (
> "extract(epoch FROM now() - {0})",
> SQLDataType.INTEGER,
> CLTS.COL_PACKET_WHEN
> );
> Field<Integer> daysCalc = secsCalc.div(3600).cast(SQLDataType.DECIMAL)
> .div( 24).cast(SQLDataType.INTEGER);
The important difference is that I cast to something which is
compatible with the floating-point runtime type manually. Though, I
would have expected this isn't necessary, because I don't need to care
when simply forcefully casting to INTEGER.
What I recognized as well: SQLDataType.DOUBLE doesn't work, because
that renders to "double" in Postgres instead of "double precision" and
the former doesn't exist in my Postgres 11.
Is that as expected as well?
Thanks!
Mit freundlichen Grüßen,
Thorsten Schöning
--
Thorsten Schöning E-Mail: Thorsten....@AM-SoFT.de
AM-SoFT IT-Systeme
http://www.AM-SoFT.de/
Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04
AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow