Skip to content

Commit

Permalink
document the syntax sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Nov 17, 2024
1 parent 2c08833 commit 85a39bd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions documentation/src/main/asciidoc/querylanguage/Expressions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,18 @@ select substring(title, 1, position(' for Dummies' in title)) from Book
select substring(title from 1 for position(' for Dummies' in title)) from Book /* ANSI SQL-style */
----

Alternatively, slicing may be performed using an operator, which is just syntax sugar for the `substring()` function:

[source, hql]
----
select title[1:position(' for Dummies' in title)] from Book /* Operator-style */
----

[source,hql]
----
select name.first[1]||name.last[1] as initials from Author
----

[discrete]
===== Trimming strings
The `trim()` function follows the syntax and semantics of ANSI SQL.
Expand Down Expand Up @@ -1179,6 +1191,21 @@ On supported platforms, HQL provides a rich suite of functions for working with:
- link:{doc-user-guide-url}#hql-functions-xml[XML]

The use of these functions is outside the scope of this guide.
However, we note that the following language constructs work with arrays, and are implemented as syntactic sugar for the underlying functions:

[[array-syntax-sugar]]
|===
| Syntax | Interpretation

| `[1, 2]` | Instantiate an array
| `array[1]` | Array element
| `array[1:2]` | Array slice
| `length(array)` | Length of an array
| `position(element in array)` | Position of an element within an array
| `cast(array as String)` | Typecast array to string
| `element in array` or `array contains element` | Determine if an element belongs to an array
| `array includes subarray` | Determine if the elements of one array include all the elements of a second array
|===

[[embedding-sql]]
==== Embedding SQL expressions
Expand Down

0 comments on commit 85a39bd

Please # to comment.