Skip to content

Commit 779d9c9

Browse files
committed
document the syntax sugar
1 parent 65312cc commit 779d9c9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

documentation/src/main/asciidoc/querylanguage/Expressions.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,18 @@ select substring(title, 1, position(' for Dummies' in title)) from Book
900900
select substring(title from 1 for position(' for Dummies' in title)) from Book /* ANSI SQL-style */
901901
----
902902

903+
Alternatively, slicing may be performed using an operator, which is just syntax sugar for the `substring()` function:
904+
905+
[source, hql]
906+
----
907+
select title[1:position(' for Dummies' in title)] from Book /* Operator-style */
908+
----
909+
910+
[source,hql]
911+
----
912+
select name.first[1]||name.last[1] as initials from Author
913+
----
914+
903915
[discrete]
904916
===== Trimming strings
905917
The `trim()` function follows the syntax and semantics of ANSI SQL.
@@ -1179,6 +1191,21 @@ On supported platforms, HQL provides a rich suite of functions for working with:
11791191
- link:{doc-user-guide-url}#hql-functions-xml[XML]
11801192

11811193
The use of these functions is outside the scope of this guide.
1194+
However, we note that the following language constructs work with arrays, and are implemented as syntactic sugar for the underlying functions:
1195+
1196+
[[array-syntax-sugar]]
1197+
|===
1198+
| Syntax | Interpretation
1199+
1200+
| `[1, 2]` | Instantiate an array
1201+
| `array[1]` | Array element
1202+
| `array[1:2]` | Array slice
1203+
| `length(array)` | Length of an array
1204+
| `position(element in array)` | Position of an element within an array
1205+
| `cast(array as String)` | Typecast array to string
1206+
| `element in array` or `array contains element` | Determine if an element belongs to an array
1207+
| `array includes subarray` | Determine if the elements of one array include all the elements of a second array
1208+
|===
11821209

11831210
[[embedding-sql]]
11841211
==== Embedding SQL expressions

0 commit comments

Comments
 (0)