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

Column expressions

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

Column expressions can be used in various SQL clauses in order to refer to one or several columns. This chapter explains how to form various types of column expressions with jOOQ. A particular type of column expression is given in the section about tuples or row value expressions, where an expression may have a degree of more than one.

Using column expressions in jOOQ

jOOQ allows you to freely create arbitrary column expressions using a fluent expression construction API. Many expressions can be formed as functions from DSL methods, other expressions can be formed based on a pre-existing column expression. For example:

// A regular table column expression
Field<String> field1 = BOOK.TITLE;

// A function created from the DSL
Field<String> field2 = trim(BOOK.TITLE);

// More complex function with advanced DSL syntax
Field<String> field4 = listAgg(BOOK.TITLE)
                          .withinGroupOrderBy(BOOK.ID.asc())
                          .over().partitionBy(AUTHOR.ID);

Table of contents

3.11.1.
Table columns
3.11.1.1.
Generated table columns
3.11.1.2.
Dereferenced table columns
3.11.1.3.
Named table columns
3.11.2.
Aliased columns
3.11.3.
Cast expressions
3.11.4.
Cast expressions (with TRY_CAST) (new)
3.11.5.
Datatype coercions
3.11.6.
Readonly columns
3.11.7.
Computed columns
3.11.8.
Collations
3.11.9.
Arithmetic expressions
3.11.10.
String concatenation
3.11.11.
Case sensitivity with strings
3.11.12.
General functions
3.11.12.1.
CHOOSE
3.11.12.2.
COALESCE
3.11.12.3.
DECODE
3.11.12.4.
IIF
3.11.12.5.
NULLIF
3.11.12.6.
NVL
3.11.12.7.
NVL2
3.11.13.
Numeric functions
3.11.13.1.
ABS
3.11.13.2.
ACOS
3.11.13.3.
ASIN
3.11.13.4.
ATAN
3.11.13.5.
ATAN2
3.11.13.6.
CEIL
3.11.13.7.
COS
3.11.13.8.
COSH
3.11.13.9.
COT
3.11.13.10.
COTH
3.11.13.11.
DEG
3.11.13.12.
E
3.11.13.13.
EXP
3.11.13.14.
FLOOR
3.11.13.15.
GREATEST
3.11.13.16.
LEAST
3.11.13.17.
LN
3.11.13.18.
LOG
3.11.13.19.
LOG10
3.11.13.20.
NEG
3.11.13.21.
PI
3.11.13.22.
POWER
3.11.13.23.
RAD
3.11.13.24.
RAND
3.11.13.25.
ROUND
3.11.13.26.
SIGN
3.11.13.27.
SIN
3.11.13.28.
SINH
3.11.13.29.
SQRT
3.11.13.30.
SQUARE
3.11.13.31.
TAN
3.11.13.32.
TANH
3.11.13.33.
TRUNC
3.11.13.34.
WIDTH_BUCKET
3.11.14.
Bitwise functions
3.11.14.1.
BIT_AND
3.11.14.2.
BIT_COUNT
3.11.14.3.
BIT_GET
3.11.14.4.
BIT_NAND
3.11.14.5.
BIT_NOR
3.11.14.6.
BIT_NOT
3.11.14.7.
BIT_OR
3.11.14.8.
BIT_SET
3.11.14.9.
BIT_XNOR
3.11.14.10.
BIT_XOR
3.11.14.11.
SHL
3.11.14.12.
SHR
3.11.15.
String functions
3.11.15.1.
ASCII
3.11.15.2.
BIT_LENGTH
3.11.15.3.
CHR
3.11.15.4.
CONCAT (|| operator)
3.11.15.5.
DIGITS
3.11.15.6.
LEFT
3.11.15.7.
LENGTH
3.11.15.8.
LOWER
3.11.15.9.
LPAD
3.11.15.10.
LTRIM
3.11.15.11.
MD5
3.11.15.12.
MID
3.11.15.13.
OCTET_LENGTH
3.11.15.14.
OVERLAY
3.11.15.15.
POSITION
3.11.15.16.
REGEXP_REPLACE
3.11.15.17.
REPEAT
3.11.15.18.
REPLACE
3.11.15.19.
REVERSE
3.11.15.20.
RIGHT
3.11.15.21.
RPAD
3.11.15.22.
RTRIM
3.11.15.23.
SPACE
3.11.15.24.
SPLIT_PART
3.11.15.25.
SUBSTRING
3.11.15.26.
SUBSTRING_INDEX
3.11.15.27.
TO_CHAR
3.11.15.28.
TO_HEX
3.11.15.29.
TRANSLATE
3.11.15.30.
TRIM
3.11.15.31.
UPPER
3.11.15.32.
UUID
3.11.16.
Datetime functions
3.11.16.1.
CENTURY
3.11.16.2.
CURRENT_DATE
3.11.16.3.
CURRENT_LOCALDATE
3.11.16.4.
CURRENT_LOCALDATETIME
3.11.16.5.
CURRENT_LOCALTIME
3.11.16.6.
CURRENT_OFFSETDATETIME
3.11.16.7.
CURRENT_OFFSETTIME
3.11.16.8.
CURRENT_TIME
3.11.16.9.
CURRENT_TIMESTAMP
3.11.16.10.
DATE
3.11.16.11.
DATEADD
3.11.16.12.
DATEDIFF
3.11.16.13.
DATESUB
3.11.16.14.
DAY
3.11.16.15.
DAY_OF_YEAR
3.11.16.16.
DECADE
3.11.16.17.
EPOCH
3.11.16.18.
EXTRACT
3.11.16.19.
HOUR
3.11.16.20.
ISO_DAY_OF_WEEK
3.11.16.21.
LOCALDATE
3.11.16.22.
LOCALDATEADD
3.11.16.23.
LOCALDATESUB
3.11.16.24.
LOCALDATETIME
3.11.16.25.
LOCALDATETIMEADD
3.11.16.26.
LOCALDATETIMESUB
3.11.16.27.
LOCALTIME
3.11.16.28.
MILLENNIUM
3.11.16.29.
MINUTE
3.11.16.30.
MONTH
3.11.16.31.
QUARTER
3.11.16.32.
SECOND
3.11.16.33.
TIME
3.11.16.34.
TIMESTAMP
3.11.16.35.
TIMESTAMPADD
3.11.16.36.
TIMESTAMPSUB
3.11.16.37.
TO_DATE
3.11.16.38.
TO_LOCALDATE
3.11.16.39.
TO_LOCALDATETIME
3.11.16.40.
TO_TIMESTAMP
3.11.16.41.
TRUNC
3.11.16.42.
YEAR
3.11.17.
ARRAY functions
3.11.17.1.
ARRAY_APPEND (|| operator)
3.11.17.2.
ARRAY_CONCAT (|| operator)
3.11.17.3.
ARRAY_GET
3.11.17.4.
ARRAY_OVERLAP
3.11.17.5.
ARRAY_PREPEND (|| operator)
3.11.17.6.
ARRAY_REMOVE
3.11.17.7.
ARRAY_REPLACE
3.11.17.8.
ARRAY constructor
3.11.17.9.
ARRAY constructor from subquery
3.11.17.10.
CARDINALITY
3.11.18.
JSON functions
3.11.18.1.
JSON_ARRAY
3.11.18.2.
JSON_INSERT
3.11.18.3.
JSON_KEYS
3.11.18.4.
JSON_OBJECT
3.11.18.5.
JSON_REMOVE
3.11.18.6.
JSON_REPLACE
3.11.18.7.
JSON_SET
3.11.18.8.
JSON_VALUE
3.11.18.9.
JSON array element access with -> or ->>
3.11.18.10.
JSON object attribute access with -> or ->>
3.11.19.
XML functions
3.11.19.1.
XMLATTRIBUTES
3.11.19.2.
XMLCOMMENT
3.11.19.3.
XMLCONCAT
3.11.19.4.
XMLDOCUMENT
3.11.19.5.
XMLELEMENT
3.11.19.6.
XMLFOREST
3.11.19.7.
XMLPARSE
3.11.19.8.
XMLPI
3.11.19.9.
XMLQUERY
3.11.19.10.
XMLSERIALIZE
3.11.20.
System functions
3.11.20.1.
CURRENT_SCHEMA
3.11.20.2.
CURRENT_USER
3.11.21.
Spatial functions
3.11.21.1.
ST_Area
3.11.21.2.
ST_AsText
3.11.21.3.
ST_Centroid
3.11.21.4.
ST_Difference
3.11.21.5.
ST_Distance
3.11.21.6.
ST_EndPoint
3.11.21.7.
ST_ExteriorRing
3.11.21.8.
ST_GeometryN
3.11.21.9.
ST_GeometryType
3.11.21.10.
ST_GeomFromText
3.11.21.11.
ST_InteriorRingN
3.11.21.12.
ST_Intersection
3.11.21.13.
ST_Length
3.11.21.14.
ST_NumGeometries
3.11.21.15.
ST_NumInteriorRings
3.11.21.16.
ST_NumPoints
3.11.21.17.
ST_PointN
3.11.21.18.
ST_SRID
3.11.21.19.
ST_StartPoint
3.11.21.20.
ST_Union
3.11.21.21.
ST_X
3.11.21.22.
ST_Y
3.11.21.23.
ST_Z
3.11.22.
Aggregate functions
3.11.22.1.
Grouping
3.11.22.2.
Distinctness
3.11.22.3.
Filtering
3.11.22.4.
Ordering
3.11.22.5.
Ordering WITHIN GROUP
3.11.22.6.
Keeping
3.11.22.7.
ANY_VALUE
3.11.22.8.
ARRAY_AGG
3.11.22.9.
AVG
3.11.22.10.
BIT_AND_AGG
3.11.22.11.
BIT_NAND_AGG
3.11.22.12.
BIT_NOR_AGG
3.11.22.13.
BIT_OR_AGG
3.11.22.14.
BIT_XOR_AGG
3.11.22.15.
BIT_XNOR_AGG
3.11.22.16.
BOOL_AND
3.11.22.17.
BOOL_OR
3.11.22.18.
COLLECT
3.11.22.19.
COUNT
3.11.22.20.
CUME_DIST
3.11.22.21.
DENSE_RANK
3.11.22.22.
EVERY
3.11.22.23.
GROUP_CONCAT
3.11.22.24.
JSON_ARRAYAGG
3.11.22.25.
JSON_OBJECTAGG
3.11.22.26.
LISTAGG
3.11.22.27.
MAX
3.11.22.28.
MEDIAN
3.11.22.29.
MIN
3.11.22.30.
MODE
3.11.22.31.
MULTISET_AGG
3.11.22.32.
PERCENT_RANK
3.11.22.33.
PERCENTILE_CONT
3.11.22.34.
PERCENTILE_DISC
3.11.22.35.
PRODUCT
3.11.22.36.
RANK
3.11.22.37.
SUM
3.11.22.38.
XMLAGG
3.11.23.
Window functions
3.11.23.1.
PARTITION BY
3.11.23.2.
ORDER BY
3.11.23.3.
ROWS, RANGE, GROUPS (frame clause)
3.11.23.4.
EXCLUDE
3.11.23.5.
NULL treatment
3.11.23.6.
FROM FIRST, FROM LAST
3.11.23.7.
Nested aggregate functions
3.11.23.8.
Window aggregation
3.11.23.9.
Window ordered aggregate
3.11.23.10.
ROW_NUMBER
3.11.23.11.
RANK
3.11.23.12.
DENSE_RANK
3.11.23.13.
PERCENT_RANK
3.11.23.14.
CUME_DIST
3.11.23.15.
NTILE
3.11.23.16.
LEAD
3.11.23.17.
LAG
3.11.23.18.
FIRST_VALUE
3.11.23.19.
LAST_VALUE
3.11.23.20.
NTH_VALUE
3.11.24.
User-defined functions
3.11.25.
User-defined aggregate functions
3.11.26.
User-defined type attribute paths (new)
3.11.27.
The CASE expression
3.11.28.
Sequences and serials
3.11.29.
Scalar subqueries
3.11.30.
ARRAY value constructor
3.11.31.
MULTISET value constructor
3.11.32.
Tuples or row value expressions
3.11.33.
Nested records

previous : next

Feedback

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

The jOOQ Logo