Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions documentation/src/main/asciidoc/querylanguage/Expressions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ The following special functions make it possible to discover or narrow expressio
| `cast()` | Narrow a basic type | `cast(x as Type)` | ✔
| `str()` | Cast to a string | `str(x)` | ✖
| `ordinal()` | Get the ordinal value of an enum | `ordinal(x)` | ✖
| `string()` | Get the string-valued name of an enum | `string(x)` | ✖
|===

Let's see what these functions do.
Expand Down Expand Up @@ -647,16 +648,17 @@ select str(id) from Order

[[function-ordinal]]
[discrete]
===== Extracting the ordinal value of an enum
===== Extracting the ordinal value or name of an enum

The function `ordinal(x)` extracts the ordinal value of an enum.
It supports both enum fields mapped as `ORDINAL` and `STRING`.
The function `ordinal(x)` extracts the ordinal value of an enum, and the function `string(x)` extracts the name of the enum value as a string.

[source, hql]
----
select ordinal(p.type) from Phone p
select ordinal(p.type), string(p.type) from Phone p
----

Both functions work with enum fields mapped as `ORDINAL` and with enum fields mapped as `STRING`.

[[functions-null]]
==== Functions for working with null values

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,11 @@ public int ordinal() {
* <li> <code>ifnull(arg0, arg1)</code> - synonym of <code>coalesce(a, b)</code>
* </ul>
*
* <ul>
* <li> <code>ordinal(arg)</code>
* <li> <code>string(arg)</code>
* </ul>
*
* Finally, the following functions are defined as abbreviations for
* <code>extract()</code>, and desugared by the parser:
*
Expand Down