Available in versions: Dev (3.20) | Latest (3.19)

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

User-defined type attribute paths

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

jOOQ's code generator supports user-defined types (UDTs) and generates meta data, records, POJOs and other artifacts for those types.

When dereferencing such types in SQL, you can access the org.jooq.UDTRecord as follows. Assumnig this schema using PostgreSQL syntax:

CREATE TYPE country AS (
  iso_code TEXT,
  description TEXT
);

CREATE TYPE name AS (
  first_name TEXT,
  last_name TEXT
);

CREATE TYPE address AS (
  street TEXT,
  number TEXT,
  zip TEXT,
  city TEXT,
  country COUNTRY
);

CREATE TABLE customer (
  id INT PRIMARY KEY,
  name NAME,
  address ADDRESS
);

This data can be fetched with jOOQ as follows:

Record2<NameRecord, AddressRecord> result =
create.select(CUSTOMER.NAME, CUSTOMER.ADDRESS)
      .from(CUSTOMER)
      .where(CUSTOMER.ID.eq(1))
      .fetchOne();

System.out.println(result.value1().getFirstName());
System.out.println(result.value1().getLastName());
System.out.println(result.value2().getCountry().getIsoCode());

If you don't need to fetch the entire UDT, you can also dereference individual attributes directly in SQL, in a type safe way!

Record3<String, String, String> result =
create.select(
          CUSTOMER.NAME.FIRST_NAME,
          CUSTOMER.NAME.LAST_NAME,
          CUSTOMER.ADDRESS.COUNTRY.ISO_CODE)
      .from(CUSTOMER)
      .where(CUSTOMER.ID.eq(1))
      .fetchOne();

System.out.println(result.value1());
System.out.println(result.value2());
System.out.println(result.value3());

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo