Operators Stay organized with collections Save and categorize content based on your preferences.
GoogleSQL for Bigtable supports operators.Operators are represented by special characters or keywords; they don't usefunction call syntax. An operator manipulates any number of data inputs, alsocalled operands, and returns a result.
Common conventions:
- Unless otherwise specified, all operators return
NULLwhen one of theoperands isNULL. - All operators will throw an error if the computation result overflows.
- For all floating point operations,
+/-infandNaNmay only be returnedif one of the operands is+/-inforNaN. In other cases, an error isreturned.
Operator precedence
The following table lists all GoogleSQL operators from highest tolowest precedence, i.e., the order in which they will be evaluated within astatement.
| Order of Precedence | Operator | Input Data Types | Name | Operator Arity |
|---|---|---|---|---|
| 1 | Field access operator | STRUCT | Field access operator | Binary |
| Array subscript operator | ARRAY | Array position. Must be used withOFFSET orORDINAL—seeArray Functions. | Binary | |
| 2 | + | All numeric types | Unary plus | Unary |
- | All numeric types | Unary minus | Unary | |
~ | Integer orBYTES | Bitwise not | Unary | |
| 3 | * | All numeric types | Multiplication | Binary |
/ | All numeric types | Division | Binary | |
|| | STRING,BYTES, orARRAY<T> | Concatenation operator | Binary | |
| 4 | + | All numeric types,DATE withINT64 | Addition | Binary |
- | All numeric types,DATE withINT64 | Subtraction | Binary | |
| 5 | << | Integer orBYTES | Bitwise left-shift | Binary |
>> | Integer orBYTES | Bitwise right-shift | Binary | |
| 6 | & | Integer orBYTES | Bitwise and | Binary |
| 7 | ^ | Integer orBYTES | Bitwise xor | Binary |
| 8 | | | Integer orBYTES | Bitwise or | Binary |
| 9 (Comparison Operators) | = | Any comparable type. SeeData Types for a complete list. | Equal | Binary |
< | Any comparable type. SeeData Types for a complete list. | Less than | Binary | |
> | Any comparable type. SeeData Types for a complete list. | Greater than | Binary | |
<= | Any comparable type. SeeData Types for a complete list. | Less than or equal to | Binary | |
>= | Any comparable type. SeeData Types for a complete list. | Greater than or equal to | Binary | |
!=,<> | Any comparable type. SeeData Types for a complete list. | Not equal | Binary | |
[NOT] LIKE | STRING andBYTES | Value does [not] match the pattern specified | Binary | |
[NOT] BETWEEN | Any comparable types. SeeData Types for a complete list. | Value is [not] within the range specified | Binary | |
[NOT] IN | Any comparable types. SeeData Types for a complete list. | Value is [not] in the set of values specified | Binary | |
IS [NOT] NULL | All | Value is [not]NULL | Unary | |
IS [NOT] TRUE | BOOL | Value is [not]TRUE. | Unary | |
IS [NOT] FALSE | BOOL | Value is [not]FALSE. | Unary | |
| 10 | NOT | BOOL | LogicalNOT | Unary |
| 11 | AND | BOOL | LogicalAND | Binary |
| 12 | OR | BOOL | LogicalOR | Binary |
For example, the logical expression:
x OR y AND z
is interpreted as:
( x OR ( y AND z ) )
Operators with the same precedence are left associative. This means that thoseoperators are grouped together starting from the left and moving right. Forexample, the expression:
x AND y AND z
is interpreted as:
( ( x AND y ) AND z )
The expression:
x * y / z
is interpreted as:
( ( x * y ) / z )
All comparison operators have the same priority, but comparison operatorsaren't associative. Therefore, parentheses are required to resolveambiguity. For example:
(x < y) IS FALSE
Operator list
| Name | Summary |
|---|---|
| Field access operator | Gets the value of a field. |
| Array subscript operator | Gets a value from an array at a specific position. |
| Arithmetic operators | Performs arithmetic operations. |
| Date arithmetics operators | Performs arithmetic operations on dates. |
| Bitwise operators | Performs bit manipulation. |
| Logical operators | Tests for the truth of some condition and producesTRUE,FALSE, orNULL. |
| Comparison operators | Compares operands and produces the results of the comparison as aBOOL value. |
IS operators | Checks for the truth of a condition and produces eitherTRUE orFALSE. |
LIKE operator | Checks if values are like or not like one another. |
| Concatenation operator | Combines multiple values into one. |
Field access operator
expression.fieldname[....]Description
Gets the value of a field. Alternatively known as the dot operator. Can beused to access nested fields. For example,expression.fieldname1.fieldname2.
Input values:
STRUCT
Return type
- For
STRUCT: SQL data type offieldname. If a field isn't found inthe struct, an error is thrown.
Example
In the following example, the field access operations are.address and.country.
SELECTSTRUCT(STRUCT('Yonge Street'ASstreet,'Canada'AScountry)ASaddress).address.country/*---------+ | country | +---------+ | Canada | +---------*/Array subscript operator
Note: Syntax characters enclosed in double quotes ("") are literal andrequired.array_expression"["array_subscript_specifier"]"array_subscript_specifier:{index|position_keyword(index)}position_keyword:{OFFSET|SAFE_OFFSET|ORDINAL|SAFE_ORDINAL}Description
Gets a value from an array at a specific position.
Input values:
array_expression: The input array.position_keyword(index): Determines where the index for the array shouldstart and how out-of-range indexes are handled. The index is an integer thatrepresents a specific position in the array.OFFSET(index): The index starts at zero. Produces an error if the index isout of range. To produceNULLinstead of an error, useSAFE_OFFSET(index). Thisposition keyword produces the same result asindexby itself.SAFE_OFFSET(index): The index starts atzero. ReturnsNULLif the index is out of range.ORDINAL(index): The index starts at one.Produces an error if the index is out of range.To produceNULLinstead of an error, useSAFE_ORDINAL(index).SAFE_ORDINAL(index): The index starts atone. ReturnsNULLif the index is out of range.
index: An integer that represents a specific position in the array. If usedby itself without a position keyword, the index starts at zero and producesan error if the index is out of range. To produceNULLinstead of an error,use theSAFE_OFFSET(index)orSAFE_ORDINAL(index)position keyword.
Return type
T wherearray_expression isARRAY<T>.
Examples
In following query, the array subscript operator is used to return values atspecific position initem_array. This query also shows what happens when youreference an index (6) in an array that's out of range. If theSAFE prefixis included,NULL is returned, otherwise an error is produced.
SELECT["coffee","tea","milk"]ASitem_array,["coffee","tea","milk"][0]ASitem_index,["coffee","tea","milk"][OFFSET(0)]ASitem_offset,["coffee","tea","milk"][ORDINAL(1)]ASitem_ordinal,["coffee","tea","milk"][SAFE_OFFSET(6)]ASitem_safe_offset/*---------------------+------------+-------------+--------------+------------------+ | item_array | item_index | item_offset | item_ordinal | item_safe_offset | +---------------------+------------+-------------+--------------+------------------+ | [coffee, tea, milk] | coffee | coffee | coffee | NULL | +----------------------------------+-------------+--------------+------------------*/When you reference an index that's out of range in an array, and a positionalkeyword that begins withSAFE isn't included, an error is produced.For example:
-- Error. Array index 6 is out of bounds.SELECT["coffee","tea","milk"][6]ASitem_offset-- Error. Array index 6 is out of bounds.SELECT["coffee","tea","milk"][OFFSET(6)]ASitem_offsetThe following queries contain an array subscript operator that's appliedto a column family calledcell_plan in a table called[test_table][test-table]:
SELECTMAP_KEYS(cell_plan)[0]ASresultsFROMtest_tableLIMIT1/*----------------+ | results | +----------------+ | data_plan_01gb | +----------------*/SELECTMAP_KEYS(cell_plan)[1]ASresultsFROMtest_tableLIMIT1/*----------------+ | results | +----------------+ | data_plan_05gb | +----------------*/SELECTMAP_KEYS(cell_plan)[OFFSET(1)]ASresultsFROMtest_tableLIMIT1/*----------------+ | results | +----------------+ | data_plan_05gb | +----------------*/SELECTMAP_KEYS(cell_plan)[ORDINAL(0)]ASresultsFROMtest_tableLIMIT1/*----------------+ | results | +----------------+ | data_plan_01gb | +----------------*/SELECTMAP_KEYS(cell_plan)[SAFE_OFFSET(5)]ASresultsFROMtest_tableLIMIT1/*----------------+ | results | +----------------+ | NULL | +----------------*/Arithmetic operators
All arithmetic operators accept input of numeric typeT, and the result typehas typeT unless otherwise indicated in the description below:
| Name | Syntax |
|---|---|
| Addition | X + Y |
| Subtraction | X - Y |
| Multiplication | X * Y |
| Division | X / Y |
| Unary Plus | + X |
| Unary Minus | - X |
NOTE: Divide by zero operations return an error. To return a different result,consider theIEEE_DIVIDE orSAFE_DIVIDE functions.
Result types for Addition, Subtraction and Multiplication:
| INPUT | INT64 | FLOAT32 | FLOAT64 |
|---|---|---|---|
INT64 | INT64 | FLOAT64 | FLOAT64 |
FLOAT32 | FLOAT64 | FLOAT64 | FLOAT64 |
FLOAT64 | FLOAT64 | FLOAT64 | FLOAT64 |
Result types for Division:
| INPUT | INT64 | FLOAT32 | FLOAT64 |
|---|---|---|---|
INT64 | FLOAT64 | FLOAT64 | FLOAT64 |
FLOAT32 | FLOAT64 | FLOAT64 | FLOAT64 |
FLOAT64 | FLOAT64 | FLOAT64 | FLOAT64 |
Result types for Unary Plus:
| INPUT | INT64 | FLOAT32 | FLOAT64 |
|---|---|---|---|
| OUTPUT | INT64 | FLOAT32 | FLOAT64 |
Result types for Unary Minus:
| INPUT | INT64 | FLOAT32 | FLOAT64 |
|---|---|---|---|
| OUTPUT | INT64 | FLOAT32 | FLOAT64 |
Date arithmetics operators
Operators '+' and '-' can be used for arithmetic operations on dates.
date_expression+int64_expressionint64_expression+date_expressiondate_expression-int64_expressionDescription
Adds or subtractsint64_expression days to or fromdate_expression. This isequivalent toDATE_ADD orDATE_SUB functions, when interval is expressed indays.
Return Data Type
DATE
Example
SELECTDATE"2020-09-22"+1ASday_later,DATE"2020-09-22"-7ASweek_ago/*------------+------------+ | day_later | week_ago | +------------+------------+ | 2020-09-23 | 2020-09-15 | +------------+------------*/Bitwise operators
All bitwise operators return the same type and the same length asthe first operand.
| Name | Syntax | Input Data Type | Description |
|---|---|---|---|
| Bitwise not | ~ X | Integer orBYTES | Performs logical negation on each bit, forming the ones' complement of thegiven binary value. |
| Bitwise or | X | Y | X: Integer orBYTESY: Same type asX | Takes two bit patterns of equal length and performs the logical inclusiveOR operation on each pair of the corresponding bits.This operator throws an error ifX andY are bytes ofdifferent lengths. |
| Bitwise xor | X ^ Y | X: Integer orBYTESY: Same type asX | Takes two bit patterns of equal length and performs thelogical exclusiveOR operation on each pair of the correspondingbits.This operator throws an error ifX andY are bytes ofdifferent lengths. |
| Bitwise and | X & Y | X: Integer orBYTESY: Same type asX | Takes two bit patterns of equal length and performs thelogicalAND operation on each pair of the corresponding bits.This operator throws an error ifX andY are bytes ofdifferent lengths. |
| Left shift | X << Y | X: Integer orBYTESY:INT64 | Shifts the first operandX to the left.This operator returns0 or a byte sequence ofb'\x00'if the second operandY is greater than or equal tothe bit length of the first operandX (for example,64ifX has the typeINT64).This operator throws an error ifY is negative. |
| Right shift | X >> Y | X: Integer orBYTESY:INT64 | Shifts the first operandX to the right. This operator doesn'tperform sign bit extension with a signed type (i.e., it fills vacant bits on the leftwith0). This operator returns0 or a byte sequence ofb'\x00'if the second operandY is greater than or equal tothe bit length of the first operandX (for example,64ifX has the typeINT64).This operator throws an error ifY is negative. |
Logical operators
GoogleSQL supports theAND,OR, andNOT logical operators.Logical operators allow onlyBOOL orNULL inputand usethree-valued logicto produce a result. The result can beTRUE,FALSE, orNULL:
x | y | x AND y | x OR y |
|---|---|---|---|
TRUE | TRUE | TRUE | TRUE |
TRUE | FALSE | FALSE | TRUE |
TRUE | NULL | NULL | TRUE |
FALSE | TRUE | FALSE | TRUE |
FALSE | FALSE | FALSE | FALSE |
FALSE | NULL | FALSE | NULL |
NULL | TRUE | NULL | TRUE |
NULL | FALSE | FALSE | NULL |
NULL | NULL | NULL | NULL |
x | NOT x |
|---|---|
TRUE | FALSE |
FALSE | TRUE |
NULL | NULL |
The order of evaluation of operands toAND andOR can vary, and evaluationcan be skipped if unnecessary.
Examples
The examples in this section reference a table calledentry_table:
/*-------+ | entry | +-------+ | a | | b | | c | | NULL | +-------*/SELECT'a'FROMentry_tableWHEREentry='a'-- a => 'a' = 'a' => TRUE-- b => 'b' = 'a' => FALSE-- NULL => NULL = 'a' => NULL/*-------+ | entry | +-------+ | a | +-------*/SELECTentryFROMentry_tableWHERENOT(entry='a')-- a => NOT('a' = 'a') => NOT(TRUE) => FALSE-- b => NOT('b' = 'a') => NOT(FALSE) => TRUE-- NULL => NOT(NULL = 'a') => NOT(NULL) => NULL/*-------+ | entry | +-------+ | b | | c | +-------*/SELECTentryFROMentry_tableWHEREentryISNULL-- a => 'a' IS NULL => FALSE-- b => 'b' IS NULL => FALSE-- NULL => NULL IS NULL => TRUE/*-------+ | entry | +-------+ | NULL | +-------*/Comparison operators
Compares operands and produces the results of the comparison as aBOOLvalue. These comparison operators are available:
| Name | Syntax | Description |
|---|---|---|
| Less Than | X < Y | ReturnsTRUE ifX is less thanY. This operator supports specifyingcollation. |
| Less Than or Equal To | X <= Y | ReturnsTRUE ifX is less than or equal toY. This operator supports specifyingcollation. |
| Greater Than | X > Y | ReturnsTRUE ifX is greater thanY. This operator supports specifyingcollation. |
| Greater Than or Equal To | X >= Y | ReturnsTRUE ifX is greater than or equal toY. This operator supports specifyingcollation. |
| Equal | X = Y | ReturnsTRUE ifX is equal toY. This operator supports specifyingcollation. |
| Not Equal | X != YX <> Y | ReturnsTRUE ifX isn't equal toY. This operator supports specifyingcollation. |
BETWEEN | X [NOT] BETWEEN Y AND Z | Returns |
LIKE | X [NOT] LIKE Y | See the`LIKE` operator for details. |
IN | Multiple | See the`IN` operator for details. |
The following rules apply to operands in a comparison operator:
- The operands must becomparable.
- A comparison operator generally requires both operands to be of thesame type.
- If the operands are of different types, and the values of those types can beconverted to a common type without loss of precision,they are generally coerced to that common type for the comparison.
- A literal operand is generally coerced to the same data type of anon-literal operand that's part of the comparison.
- Struct operands support only these comparison operators: equal(
=), not equal (!=and<>), andIN.
The following rules apply when comparing these data types:
- Floating point:All comparisons with
NaNreturnFALSE,except for!=and<>, which returnTRUE. BOOL:FALSEis less thanTRUE.STRING: Strings are compared codepoint-by-codepoint, which means thatcanonically equivalent strings are only guaranteed to compare as equal ifthey have been normalized first.NULL: Any operation with aNULLinput returnsNULL.STRUCT: When testing a struct for equality, it's possible that one or morefields areNULL. In such cases:- If all non-
NULLfield values are equal, the comparison returnsNULL. - If any non-
NULLfield values aren't equal, the comparison returnsFALSE.
The following table demonstrates how
STRUCTdata types are compared whenthey have fields that areNULLvalued.Struct1 Struct2 Struct1 = Struct2 STRUCT(1, NULL)STRUCT(1, NULL)NULLSTRUCT(1, NULL)STRUCT(2, NULL)FALSESTRUCT(1,2)STRUCT(1, NULL)NULL- If all non-
IS operators
IS operators return TRUE or FALSE for the condition they are testing. They neverreturnNULL, even forNULL inputs, unlike theIS_INF andIS_NANfunctions defined inMathematical Functions.IfNOT is present, the outputBOOL value isinverted.
| Function Syntax | Input Data Type | Result Data Type | Description |
|---|---|---|---|
X IS TRUE | BOOL | BOOL | Evaluates toTRUE ifX evaluates toTRUE. Otherwise, evaluates toFALSE. |
X IS NOT TRUE | BOOL | BOOL | Evaluates toFALSE ifX evaluates toTRUE. Otherwise, evaluates toTRUE. |
X IS FALSE | BOOL | BOOL | Evaluates toTRUE ifX evaluates toFALSE. Otherwise, evaluates toFALSE. |
X IS NOT FALSE | BOOL | BOOL | Evaluates toFALSE ifX evaluates toFALSE. Otherwise, evaluates toTRUE. |
X IS NULL | Any value type | BOOL | Evaluates toTRUE ifX evaluates toNULL. Otherwise evaluates toFALSE. |
X IS NOT NULL | Any value type | BOOL | Evaluates toFALSE ifX evaluates toNULL. Otherwise evaluates toTRUE. |
X IS UNKNOWN | BOOL | BOOL | Evaluates toTRUE ifX evaluates toNULL. Otherwise evaluates toFALSE. |
X IS NOT UNKNOWN | BOOL | BOOL | Evaluates toFALSE ifX evaluates toNULL. Otherwise, evaluates toTRUE. |
LIKE operator
expression_1[NOT]LIKEexpression_2Description
LIKE returnsTRUE if the string in the first operandexpression_1matches a pattern specified by the second operandexpression_2,otherwise returnsFALSE.
NOT LIKE returnsTRUE if the string in the first operandexpression_1doesn't match a pattern specified by the second operandexpression_2,otherwise returnsFALSE.
Expressions can contain these characters:
- A percent sign (
%) matches any number of characters or bytes. - An underscore (
_) matches a single character or byte. - You can escape
\,_, or%using two backslashes. For example,\\%. If you are using raw strings, only a single backslash isrequired. For example,r'\%'.
This operator supportscollation, but caveats apply:
- Each
%character inexpression_2represents anarbitrary string specifier. An arbitrary string specifier can representany sequence of0or more characters. A character in the expression represents itself and is considered asingle character specifier unless:
The character is a percent sign (
%).The character is an underscore (
_) and the collator isn'tund:ci.
These additional rules apply to the underscore (
_) character:If the collator isn't
und:ci, an error is produced when an underscoreisn't escaped inexpression_2.If the collator isn't
und:ci, the underscore isn't allowed when theoperands have collation specified.Somecompatibility composites, such as the fi-ligature (
fi) and thetelephone sign (℡), will produce a match if they are compared to anunderscore.A single underscore matches the idea of what a character is, based onan approximation known as agrapheme cluster.
For a contiguous sequence of single character specifiers, equalitydepends on the collator and its language tags and tailoring.
By default, the
und:cicollator doesn't fully normalize a string.Some canonically equivalent strings are considered unequal forboth the=andLIKEoperators.The
LIKEoperator with collation has the same behavior as the=operator when there are no wildcards in the strings.Character sequences with secondary or higher-weighted differences areconsidered unequal. This includes accent differences and somespecial cases.
For example there are three ways to produce German sharp
ß:\u1E9E\U00DFss
\u1E9Eand\U00DFare considered equal but differ in tertiary.They are considered equal withund:cicollation but different fromss, which has secondary differences.Character sequences with tertiary or lower-weighted differences areconsidered equal. This includes case differences andkana subtype differences, which are considered equal.
There areignorable characters defined in Unicode.Ignorable characters are ignored in the pattern matching.
Return type
BOOL
Examples
The following examples illustrate how you can check to see if the string in thefirst operand matches a pattern specified by the second operand.
-- Returns TRUESELECT'apple'LIKE'a%';-- Returns FALSESELECT'%a'LIKE'apple';-- Returns FALSESELECT'apple'NOTLIKE'a%';-- Returns TRUESELECT'%a'NOTLIKE'apple';-- Produces an errorSELECTNULLLIKE'a%';-- Produces an errorSELECT'apple'LIKENULL;The following example illustrates how to search multiple patterns in an arrayto find a match with theLIKE operator:
Concatenation operator
The concatenation operator combines multiple values into one.
| Function Syntax | Input Data Type | Result Data Type |
|---|---|---|
STRING || STRING [ || ... ] | STRING | STRING |
BYTES || BYTES [ || ... ] | BYTES | BYTES |
ARRAY<T> || ARRAY<T> [ || ... ] | ARRAY<T> | ARRAY<T> |
CONCAT function call. For example,'A' || 'B' || 'C' becomesCONCAT('A', CONCAT('B', 'C')).Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.