I'm sorry, it was a misunderstanding on my part. I thought you were looking for the implementation of getCsvField() when you were really looking for a replacement for the placeholder HOW_CAN_I_CONVERT_IT_TO_INTEGER?
Yes, DSL.cast() or Field.cast() are one way to do that in the database. If you want to take advantage of a vendor-specific conversion function, you can also resort to plain SQL in order to add support for that: http://www.jooq.org/doc/latest/manual/sql-building/plain-sql/ For instance, if this is about MySQL ( http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_convert), you could be using: public static Field<Integer> convertToSigned(Field<String> field) { return DSL.field("convert({0}, signed)", Integer.class, field); } But I don't think it will be any different from using cast(), and jOOQ ensures that cast() works in all SQL dialects. Cheers, Lukas 2015-01-29 14:26 GMT+01:00 Gavriel Fleischer <[email protected]>: > I failed to find the correct function to use, but now I found cast(), and > it seems to work so far. > > On Wed Jan 28 2015 at 12:46:28 PM Lukas Eder <[email protected]> wrote: > >> Have you tried anything so far? Where did your attempts fail? >> >> 2015-01-28 11:23 GMT+01:00 Gavriel Fleischer <[email protected]>: >> >>> Hi, >>> >>> I have a String field that contains data like: "1;2;3". I built the DSL >>> statement that gets the "2nd subfield" from this string ("2"), but it's >>> still a String, and I need to convert it to Integer. How can I do this? >>> >>> >>> >>> final Field<Integer> status = decode().when(TABLE.EVENTID.eq("vp1s"), >>> CsvSplitter.getCsvField(STATISTICSDAILYSUMMARY.EVENTVALUE, ";", >>> 1).HOW_CAN_I_CONVERT_IT_TO_INTEGER?).otherwise(0); >>> >>> >>> public class CsvSplitter { >>> public static Field<String> getCsvField(Field<String> field, String >>> delimiter, int pos); >>> } >>> >>> -- >>> 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 a topic in the >> Google Groups "jOOQ User Group" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/jooq-user/BdCCmpl47ws/unsubscribe. >> To unsubscribe from this group and all its topics, 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. > -- 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.
