Jooq: Add support for the Postgres INET data type (java.net.InetAddress)

Created on 4 Jan 2013  路  4Comments  路  Source: jOOQ/jOOQ

See this discussion here for more insight:
https://groups.google.com/d/topic/jooq-user/YErDInFpPAg/discussion

C PostgreSQL Medium Enhancement

Most helpful comment

Just a +1 here for adding inet type support to PostgresDataType - it's a built-in type that has been around since Postgres 6.4. @domdorn's above formulation works well for me here, or alternatively something that translates to/from java.net.InetAddress would also be fine.

All 4 comments

I had to do this to make it work in inserts:

   val ip = "127.0.0.1"
   val inetType = new DefaultDataType[String](SQLDialect.POSTGRES, SQLDataType.VARCHAR, "inet")

    //log login
    autologinId match {
      case None =>     e.insertInto(at.lyrix.db.core_cas.tables.Login.LOGIN,
            at.lyrix.db.core_cas.tables.Login.LOGIN.NUSERNR,
            at.lyrix.db.core_cas.tables.Login.LOGIN.DNOW,
            at.lyrix.db.core_cas.tables.Login.LOGIN.SIP, // <-- this gets mapped to TableField<LoginRecord, Object>
            at.lyrix.db.core_cas.tables.Login.LOGIN.SLANGUAGEID,
            at.lyrix.db.core_cas.tables.Login.LOGIN.SUSERAGENT
          ).values(userId, timestamp,
 DSL.value(ip).cast(inetType), 
lang, userAgent).execute()

thats how the table looks like

lyriks=> \d core_cas.login
                                                 Table "core_cas.login"
    Column    |            Type             |                                 Modifiers                                  
--------------+-----------------------------+----------------------------------------------------------------------------
 nloginnr     | integer                     | not null default nextval(('lyriks.sttlogin_nloginnr_seq'::text)::regclass)
 nusernr      | integer                     | not null
 dnow         | timestamp without time zone | not null default now()
 sip          | inet                        | not null
 suseragent   | character varying(255)      | not null
 slanguageid  | character varying(5)        | default 'de'::character varying
 nautologinnr | integer                     | 
Indexes:
    "idx_sttlogin_date2" btree (date(dnow))

@domdorn : thanks for the hint. Yes, that's one way to work around the lack of data type support. We're hoping that more of PostgreSQL's vendor-specific data types will be supported with #3248 (TypeProviders)

Just a +1 here for adding inet type support to PostgresDataType - it's a built-in type that has been around since Postgres 6.4. @domdorn's above formulation works well for me here, or alternatively something that translates to/from java.net.InetAddress would also be fine.

Thanks for the feedback, @tomdcc. We'll look again at this for 3.9

Was this page helpful?
0 / 5 - 0 ratings