From 779d9c94c9d9bd3422a7cb28679d70ecdf6feb7f Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 17 Nov 2024 13:46:04 +0100 Subject: [PATCH] document the syntax sugar --- .../asciidoc/querylanguage/Expressions.adoc | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/documentation/src/main/asciidoc/querylanguage/Expressions.adoc b/documentation/src/main/asciidoc/querylanguage/Expressions.adoc index 756899a22b..fd1191cf4f 100644 --- a/documentation/src/main/asciidoc/querylanguage/Expressions.adoc +++ b/documentation/src/main/asciidoc/querylanguage/Expressions.adoc @@ -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. @@ -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