Available in versions: Dev (3.18) | Latest (3.17) | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8

Nullability

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

Nullability is a property of a data type, and as such can be attached to the data type using various methods. The default nullability is RDBMS specific, so if you want to be vendor agnostic about nullability in your DDL, better always state it explicitly, for example:

// Specify nullability on columns
create.createTable("table")
      .column("vendor_specific_default", INTEGER)
      .column("explicit_nullable", INTEGER.nullable(false))
      .column("explicit_not_nullable", INTEGER.nullable(true))
      .execute();

Dialect support

This example using jOOQ:

createTable("table")
      .column("vendor_specific_default", INTEGER)
      .column("explicit_nullable", INTEGER.nullable(false))
      .column("explicit_not_nullable", INTEGER.nullable(true))

Translates to the following dialect specific expressions:

-- ACCESS, DB2, HANA, INFORMIX, TERADATA
CREATE TABLE table (
  vendor_specific_default integer,
  explicit_nullable integer NOT NULL,
  explicit_not_nullable integer NULL
)

-- ASE, SYBASE
CREATE TABLE table (
  vendor_specific_default int NULL,
  explicit_nullable int NOT NULL,
  explicit_not_nullable int NULL
)

-- AURORA_MYSQL, AURORA_POSTGRES, EXASOL, H2, MARIADB, MEMSQL, MYSQL, POSTGRES, REDSHIFT, SQLDATAWAREHOUSE, SQLSERVER, 
-- VERTICA, YUGABYTEDB
CREATE TABLE table (
  vendor_specific_default int,
  explicit_nullable int NOT NULL,
  explicit_not_nullable int NULL
)

-- BIGQUERY
CREATE TABLE table (
  vendor_specific_default int64,
  explicit_nullable int64 NOT NULL,
  explicit_not_nullable int64
)

-- COCKROACHDB
CREATE TABLE table (
  vendor_specific_default int4,
  explicit_nullable int4 NOT NULL,
  explicit_not_nullable int4 NULL
)

-- DERBY, HSQLDB
CREATE TABLE table (
  vendor_specific_default int,
  explicit_nullable int NOT NULL,
  explicit_not_nullable int
)

-- FIREBIRD
CREATE TABLE table (
  vendor_specific_default integer,
  explicit_nullable integer NOT NULL,
  explicit_not_nullable integer
)

-- ORACLE, SNOWFLAKE
CREATE TABLE table (
  vendor_specific_default number(10),
  explicit_nullable number(10) NOT NULL,
  explicit_not_nullable number(10) NULL
)

-- SQLITE
CREATE TABLE "table" (
  vendor_specific_default int,
  explicit_nullable int NOT NULL,
  explicit_not_nullable int NULL
)

(These are currently generated with jOOQ 3.18, see #10141), or translate your own on our website

Feedback

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

The jOOQ Logo