doc-exports/docs/dli/sqlreference/dli_08_0297.html
Su, Xiaomeng 04d4597cf3 dli_sqlreference_0511_version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2023-11-02 14:34:08 +00:00

139 lines
6.0 KiB
HTML

<a name="dli_08_0297"></a><a name="dli_08_0297"></a>
<h1 class="topictitle1">Data Manipulation Language (DML)</h1>
<div id="body8662426"><div class="section" id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_section198286378373"><h4 class="sectiontitle">Statements</h4><p id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_p682774519373"><strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b479411131317">Syntax</strong></p>
</div>
<pre class="screen" id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_screen8417439181914">INSERT INTO table_name [PARTITION part_spec] query
part_spec: (part_col_name1=val1 [, part_col_name2=val2, ...])
query:
values
| {
select
| selectWithoutFrom
| query UNION [ ALL ] query
| query EXCEPT query
| query INTERSECT query
}
[ ORDER BY orderItem [, orderItem ]* ]
[ LIMIT { count | ALL } ]
[ OFFSET start { ROW | ROWS } ]
[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY]
orderItem:
expression [ ASC | DESC ]
select:
SELECT [ ALL | DISTINCT ]
{ * | projectItem [, projectItem ]* }
FROM tableExpression
[ WHERE booleanExpression ]
[ GROUP BY { groupItem [, groupItem ]* } ]
[ HAVING booleanExpression ]
[ WINDOW windowName AS windowSpec [, windowName AS windowSpec ]* ]
selectWithoutFrom:
SELECT [ ALL | DISTINCT ]
{ * | projectItem [, projectItem ]* }
projectItem:
expression [ [ AS ] columnAlias ]
| tableAlias . *
tableExpression:
tableReference [, tableReference ]*
| tableExpression [ NATURAL ] [ LEFT | RIGHT | FULL ] JOIN tableExpression [ joinCondition ]
joinCondition:
ON booleanExpression
| USING '(' column [, column ]* ')'
tableReference:
tablePrimary
[ matchRecognize ]
[ [ AS ] alias [ '(' columnAlias [, columnAlias ]* ')' ] ]
tablePrimary:
[ TABLE ] [ [ catalogName . ] schemaName . ] tableName
| LATERAL TABLE '(' functionName '(' expression [, expression ]* ')' ')'
| UNNEST '(' expression ')'
values:
VALUES expression [, expression ]*
groupItem:
expression
| '(' ')'
| '(' expression [, expression ]* ')'
| CUBE '(' expression [, expression ]* ')'
| ROLLUP '(' expression [, expression ]* ')'
| GROUPING SETS '(' groupItem [, groupItem ]* ')'
windowRef:
windowName
| windowSpec
windowSpec:
[ windowName ]
'('
[ ORDER BY orderItem [, orderItem ]* ]
[ PARTITION BY expression [, expression ]* ]
[
RANGE numericOrIntervalExpression {PRECEDING}
| ROWS numericExpression {PRECEDING}
]
')'
matchRecognize:
MATCH_RECOGNIZE '('
[ PARTITION BY expression [, expression ]* ]
[ ORDER BY orderItem [, orderItem ]* ]
[ MEASURES measureColumn [, measureColumn ]* ]
[ ONE ROW PER MATCH ]
[ AFTER MATCH
( SKIP TO NEXT ROW
| SKIP PAST LAST ROW
| SKIP TO FIRST variable
| SKIP TO LAST variable
| SKIP TO variable )
]
PATTERN '(' pattern ')'
[ WITHIN intervalLiteral ]
DEFINE variable AS condition [, variable AS condition ]*
')'
measureColumn:
expression AS alias
pattern:
patternTerm [ '|' patternTerm ]*
patternTerm:
patternFactor [ patternFactor ]*
patternFactor:
variable [ patternQuantifier ]
patternQuantifier:
'*'
| '*?'
| '+'
| '+?'
| '?'
| '??'
| '{' { [ minRepeat ], [ maxRepeat ] } '}' ['?']
| '{' repeat '}'</pre>
<p id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_p17596813133818"><strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b2707336133">Precautions</strong></p>
<p id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_p1785417476386">Flink SQL uses a lexical policy for identifier (table, attribute, function names) similar to Java:</p>
<ul id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_ul526635473814"><li id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_li1226635433817">The case of identifiers is preserved whether they are quoted.</li><li id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_li21423582389">Identifiers are matched case-sensitively.</li><li id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_li1382812017396">Unlike Java, back-ticks allow identifiers to contain non-alphanumeric characters (for example <strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b1941184513814">SELECT a AS `my field` FROM t</strong>).</li></ul>
<p id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_p185404783816">String literals must be enclosed in single quotes (for example, <strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b333918247916">SELECT'Hello World'</strong>). Two single quotation marks are used for escaping (for example, <strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b152072121138">SELECT'It''s me.'</strong>). Unicode characters are supported in string literals. If explicit Unicode points are required, use the following syntax:</p>
<ul id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_ul163671415193916"><li id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_li336717159398">Use the backslash (\) as escaping character (default): <strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b1965763361417">SELECT U&amp;'\263A'</strong></li><li id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_li191670189390">Use a custom escaping character: <strong id="dli_08_0297__en-us_topic_0000001165951913_en-us_topic_0000001087544488_b121333462144">SELECT U&amp;'#263A' UESCAPE '#'</strong></li></ul>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0292.html">Syntax Definition</a></div>
</div>
</div>