Bigquery - 语法基础

发布时间 2023-09-11 15:48:55作者: po-A

 

Formats for quoted literals

The following table lists all of the ways you can format a quoted literal.

LiteralExamplesDescription
Quoted string
  • "abc"
  • "it's"
  • 'it\'s'
  • 'Title: "Boy"'
Quoted strings enclosed by single (') quotes can contain unescaped double (") quotes, as well as the inverse.
Backslashes (\) introduce escape sequences. See the Escape Sequences table below.
Quoted strings cannot contain newlines, even when preceded by a backslash (\).
Triple-quoted string
  • """abc"""
  • '''it's'''
  • '''Title:"Boy"'''
  • '''two
    lines'''
  • '''why\?'''
Embedded newlines and quotes are allowed without escaping - see fourth example.
Backslashes (\) introduce escape sequences. See Escape Sequences table below.
A trailing unescaped backslash (\) at the end of a line is not allowed.
End the string with three unescaped quotes in a row that match the starting quotes.
Raw string
  • r"abc+"
  • r'''abc+'''
  • r"""abc+"""
  • r'f\(abc,(.*),def\)'
Quoted or triple-quoted literals that have the raw string literal prefix (r or R) are interpreted as raw strings (sometimes described as regex strings).
Backslash characters (\) do not act as escape characters. If a backslash followed by another character occurs inside the string literal, both characters are preserved.
A raw string cannot end with an odd number of backslashes.
Raw strings are useful for constructing regular expressions. The prefix is case-insensitive.
Bytes
  • B"abc"
  • B'''abc'''
  • b"""abc"""
Quoted or triple-quoted literals that have the bytes literal prefix (b or B) are interpreted as bytes.
Raw bytes
  • br'abc+'
  • RB"abc+"
  • RB'''abc'''
A bytes literal can be interpreted as raw bytes if both the r and b prefixes are present. These prefixes can be combined in any order and are case-insensitive. For example, rb'abc*' and rB'abc*' and br'abc*' are all equivalent. See the description for raw string to learn more about what you can do with a raw literal.

Escape sequences for string and bytes literals

The following table lists all valid escape sequences for representing non-alphanumeric characters in string and bytes literals. Any sequence not in this table produces an error.

Escape SequenceDescription
\a Bell
\b Backspace
\f Formfeed
\n Newline
\r Carriage Return
\t Tab
\v Vertical Tab
\\ Backslash (\)
\? Question Mark (?)
\" Double Quote (")
\' Single Quote (')
\` Backtick (`)
\ooo Octal escape, with exactly 3 digits (in the range 0–7). Decodes to a single Unicode character (in string literals) or byte (in bytes literals).
\xhh or \Xhh Hex escape, with exactly 2 hex digits (0–9 or A–F or a–f). Decodes to a single Unicode character (in string literals) or byte (in bytes literals). Examples:
  • '\x41' == 'A'
  • '\x41B' is 'AB'
  • '\x4' is an error
\uhhhh Unicode escape, with lowercase 'u' and exactly 4 hex digits. Valid only in string literals or identifiers.
Note that the range D800-DFFF is not allowed, as these are surrogate unicode values.
\Uhhhhhhhh Unicode escape, with uppercase 'U' and exactly 8 hex digits. Valid only in string literals or identifiers.
The range D800-DFFF is not allowed, as these values are surrogate unicode values. Also, values greater than 10FFFF are not allowed.

 

 

GoogleSQL has the following reserved keywords.

ALL
AND
ANY
ARRAY
AS
ASC
ASSERT_ROWS_MODIFIED
AT
BETWEEN
BY
CASE
CAST
COLLATE
CONTAINS
CREATE
CROSS
CUBE
CURRENT
DEFAULT
DEFINE
DESC
DISTINCT
ELSE
END
ENUM
ESCAPE
EXCEPT
EXCLUDE
EXISTS
EXTRACT
FALSE
FETCH
FOLLOWING
FOR
FROM
FULL
GROUP
GROUPING
GROUPS
HASH
HAVING
IF
IGNORE
IN
INNER
INTERSECT
INTERVAL
INTO
IS
JOIN
LATERAL
LEFT
LIKE
LIMIT
LOOKUP
MERGE
NATURAL
NEW
NO
NOT
NULL
NULLS
OF
ON
OR
ORDER
OUTER
OVER
PARTITION
PRECEDING
PROTO
QUALIFY
RANGE
RECURSIVE
RESPECT
RIGHT
ROLLUP
ROWS
SELECT
SET
SOME
STRUCT
TABLESAMPLE
THEN
TO
TREAT
TRUE
UNBOUNDED
UNION
UNNEST
USING
WHEN
WHERE
WINDOW
WITH
WITHIN

Case sensitivity

GoogleSQL follows these rules for case sensitivity:

CategoryCase-sensitive?Notes
Keywords No  
Built-in Function names No  
User-Defined Function names Yes  
Table names See Notes Dataset and table names are case-sensitive unless the is_case_insensitive option is set to TRUE.
Column names No  
String values Yes  
String comparisons Yes  
Aliases within a query No  
Regular expression matching See Notes Regular expression matching is case-sensitive by default, unless the expression itself specifies that it should be case-insensitive.
LIKE matching Yes

 

ref:Lexical structure and syntax  |  BigQuery  |  Google Cloud