Skip to content

Commit

Permalink
add CAST() function in JPQL
Browse files Browse the repository at this point in the history
See #395
  • Loading branch information
gavinking committed Aug 9, 2023
1 parent 4daf494 commit 99bc871
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion spec/src/main/asciidoc/ch04-query-language.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,34 @@ part to EXTRACT.
FROM Course c WHERE c.year = EXTRACT(YEAR FROM LOCAL DATE)
----

===== Typecasts

The CAST function converts an expression of one type to an expression
of a different type.

----
string_cast_function::=
CAST(scalar_expression AS STRING)
arithmetic_cast_function::=
CAST(string_expression AS {INTEGER | LONG | FLOAT | DOUBLE})
----

The persistence provider is required to accept typecasts of the following
forms:

- any scalar expression to STRING
- any string expression to INTEGER, LONG, FLOAT, or DOUBLE

Typecast expressions are evaluated by the database, with semantics that
vary somewhat between different databases.

When a typecast occurs as a select expression, the result type of the
select expression is:

- _java.lang.String_ for a cast to STRING
- _java.lang.Integer_, _java.lang.Long_, _java.lang.Float_, or _java.lang.Double_
for a cast to INTEGER, LONG, FLOAT, or DOUBLE, respectively

===== Invocation of Predefined and User-defined Database Functions [[a5311]]

The invocation of functions other than the
Expand Down Expand Up @@ -3081,6 +3109,7 @@ arithmetic_primary ::=
aggregate_expression |
case_expression |
function_invocation |
arithmetic_cast_function |
(subquery)
string_expression ::=
state_valued_path_expression |
Expand All @@ -3090,7 +3119,8 @@ string_expression ::=
aggregate_expression |
case_expression |
function_invocation |
string_expression || string_expression
string_cast_function |
string_expression || string_expression |
(subquery)
datetime_expression ::=
state_valued_path_expression |
Expand Down Expand Up @@ -3124,6 +3154,8 @@ type_discriminator ::=
TYPE(general_identification_variable |
single_valued_object_path_expression |
input_parameter)
arithmetic_cast_function::=
CAST(string_expression AS {INTEGER | LONG | FLOAT | DOUBLE})
functions_returning_numerics ::=
LENGTH(string_expression) |
LOCATE(string_expression, string_expression[, arithmetic_expression]) |
Expand All @@ -3148,6 +3180,8 @@ functions_returning_datetime ::=
LOCAL TIME |
LOCAL DATETIME |
extract_datetime_part
string_cast_function::=
CAST(scalar_expression AS STRING)
functions_returning_strings ::=
CONCAT(string_expression, string_expression{, string_expression}*) |
SUBSTRING(string_expression, arithmetic_expression[, arithmetic_expression]) |
Expand Down

0 comments on commit 99bc871

Please sign in to comment.