Constant Expressions
Syntax
constant_expression ::= number | string | TRUE | FALSE | NULL
number ::= [MINUS] (FLOAT_CONSTANT | INT_CONSTANT | NUMBER_CONSTANT)
string ::= STRING_CONSTANT | DSTRING_CONSTANT
Semantics
The syntax for INT_CONSTANT, FLOAT_CONSTANT, NUMBER_CONSTANT, STRING_CONSTANT, and DSTRING_CONSTANT was given in the Identifiers section.
In the current version, a query can contain the following constants (a.k.a. literals):
- String
-
String literals are sequences of unicode characters enclosed in double or single quotes. String literals are translated into String items. Notice that any escape sequences appearing in a string literal will be converted to their corresponding character inside the corresponding String item.
- Integer
-
Integer literals are sequences of one or more digits. Integer literals are translated into Integer items, if their value fits in 4 bytes, into Long items, if they fit in 8 bytes, otherwise to Number items.
- Floating point
-
Floating point literals represent real numbers using decimal notation and/or exponent. Floating-point literals are translated into Double items, if possible, otherwise to Number items.
- Number
-
Number literals are integer or floating-point literals followed by the 'n' or 'N' character. Number literals are always translated into Number items.
- TRUE / FALSE
-
The TRUE and FALSE literals are translated to the boolean true and false items, respectively.
- NULL
-
The NULL literal is translated to the json null item.
Example 6-90 From the airline baggage tracking application data, fetch the list of passengers whose bags were delivered to JTR airport
SELECT fullname, bag.bagInfo.id, bag.bagInfo.tagNum
FROM BaggageInfo bag
WHERE bag.bagInfo.lastSeenStation =any "JTR"
Explanation: In the BaggageInfo
table, the lastSeenStation
field contains information on the current location of the passenger's checked luggage. In this query, you fetch the ID and tag numbers of bags that were delivered to the JTR
airport. You use the string literal "JTR" as a constant expression in the WHERE clause. Here, the bagInfo
is an array and bag.bagInfo.lastSeenStation
is a sequence. You want to retrieve any element in the sequence whose lastSeeStation
was JTR. As the Value Comparison Operators cannot operate on sequences of more than one item, you use the sequence comparison operator any
in addition to the value comparison operator '=' to compare the lastSeeStation
fields.
If a passenger carries more than one bag, the ID and tag numbers of both bags are listed in the result.
{"fullname":"Gerard Greene","id":"79039899152842","tagNum":"1765780626568"}
{"fullname":"Michelle Payne","id":"79039899186259","tagNum":"17657806247861"}
{"fullname":"Lorenzo Phil","id":["79039899187755","79039899197755"],"tagNum":["17657806240001","17657806340001"]}
{"fullname":"Lucinda Beckman","id":"79039899187755","tagNum":"17657806240001"}