diff --git a/Go/Embeddings/Go (Embedded TSQL).sublime-syntax b/Go/Embeddings/Go (Embedded TSQL).sublime-syntax new file mode 100644 index 0000000000..854c48f25e --- /dev/null +++ b/Go/Embeddings/Go (Embedded TSQL).sublime-syntax @@ -0,0 +1,19 @@ +%YAML 1.2 +--- +name: Go (Embedded T-SQL) +scope: source.go.embedded-backtick-string.tsql +version: 2 +hidden: true + +extends: Packages/Go/Embeddings/Go (Embedded Backtick String).sublime-syntax + +contexts: + match-raw-string: + # replaces Go.sublime-syntax#match-raw-string + - match: '`' + scope: meta.string.go string.quoted.backtick.go punctuation.definition.string.begin.go + embed: scope:source.tsql.go-embedded-backtick-string + embed_scope: meta.string.go meta.embedded.go source.sql.embedded.go + escape: '`' + escape_captures: + 0: meta.string.go string.quoted.backtick.go punctuation.definition.string.end.go diff --git a/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax b/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax index e128b0cd6a..00e4668473 100644 --- a/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax +++ b/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax @@ -2,7 +2,7 @@ --- name: SQL inside Go backtick string scope: source.sql.go-embedded-backtick-string -version: 1 +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax diff --git a/Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax b/Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax new file mode 100644 index 0000000000..57128ea3ff --- /dev/null +++ b/Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax @@ -0,0 +1,21 @@ +%YAML 1.2 +--- +name: T-SQL inside Go backtick string +scope: source.tsql.go-embedded-backtick-string +version: 2 +hidden: true + +extends: Packages/SQL/TSQL.sublime-syntax + +contexts: + prototype: + - meta_prepend: true + - include: scope:source.go#match-raw-text-content + + string-escape: + - meta_prepend: true + - include: scope:source.go#match-raw-string-content + + string-interpolation: + - meta_prepend: true + - include: scope:source.go#match-raw-string-content diff --git a/Go/Go.sublime-syntax b/Go/Go.sublime-syntax index 950a6f9b4e..62e97bb5c4 100644 --- a/Go/Go.sublime-syntax +++ b/Go/Go.sublime-syntax @@ -250,6 +250,9 @@ contexts: - match: (?i)sql\b scope: meta.annotation.parameters.go constant.other.language-name.go set: scope:source.go.embedded-backtick-string.sql#match-comment-magic-language-injection-inner + - match: (?i)t-?sql\b + scope: meta.annotation.parameters.go constant.other.language-name.go + set: scope:source.go.embedded-backtick-string.tsql#match-comment-magic-language-injection-inner - match: (?i)xml\b scope: meta.annotation.parameters.go constant.other.language-name.go set: scope:source.go.embedded-backtick-string.xml#match-comment-magic-language-injection-inner diff --git a/Go/tests/syntax_test_go.go b/Go/tests/syntax_test_go.go index c272763cde..37d3b4126c 100644 --- a/Go/tests/syntax_test_go.go +++ b/Go/tests/syntax_test_go.go @@ -5883,7 +5883,7 @@ func lang_embedding() { // ^ meta.string.go string.quoted.backtick.go punctuation.definition.string.begin.go // ^ meta.string.go meta.embedded.go source.sql.embedded.go update schema.table - // ^^^^^^ meta.string.go meta.embedded.go source.sql.embedded.go keyword.other.DML.sql + // ^^^^^^ meta.string.go meta.embedded.go source.sql.embedded.go keyword.other.dml.sql set some_field = null where @@ -5907,6 +5907,17 @@ func lang_embedding() { not_sql_string = `select not sql` // ^^^^^^^^^^^^^^^^ meta.string.go string.quoted.backtick.go - source.sql + //language=t-sql + // <- comment.line.double-slash.go punctuation.definition.comment.go + //^^^^^^^^^^^^^^^ comment.line.double-slash.go + //^^^^^^^^ meta.annotation.identifier.go + // ^ meta.annotation keyword.operator.assignment.go + // ^^^^^ meta.annotation.parameters.go constant.other.language-name.go + sqlQuery = ` + SELECT id + FROM ##global_temp_table;` + // ^^ punctuation.definition.variable + response := &http.Response{ StatusCode: http.StatusUnauthorized, //language=json diff --git a/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax b/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax index b2467a53ef..d8ace3203c 100644 --- a/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax @@ -1,6 +1,7 @@ %YAML 1.2 --- scope: source.sql.interpolated.php +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax @@ -10,14 +11,24 @@ contexts: - meta_prepend: true - include: Packages/PHP/PHP Source.sublime-syntax#interpolations + main: + - meta_prepend: true + # prevent stray bracket highlighting + - match: \) + scope: punctuation.section.group.end.sql + + single-identifier: + - meta_prepend: true + - meta_include_prototype: false + - include: Packages/PHP/PHP Source.sublime-syntax#interpolation + inside-like-single-quoted-string: - meta_prepend: true - - include: Packages/PHP/PHP Source.sublime-syntax#string-interpolations + - include: string-interpolation - string-escape: - # this context is included in anonymous string contexts + inside-single-quoted-string: - meta_prepend: true - - include: Packages/PHP/PHP Source.sublime-syntax#string-interpolations + - include: string-interpolation string-interpolation: # this context is included in anonymous string contexts diff --git a/PHP/Embeddings/SQL (for PHP).sublime-syntax b/PHP/Embeddings/SQL (for PHP).sublime-syntax index 361f780251..4cfcf3467c 100644 --- a/PHP/Embeddings/SQL (for PHP).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP).sublime-syntax @@ -1,6 +1,7 @@ %YAML 1.2 --- scope: source.sql.embedded.php +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax @@ -11,6 +12,12 @@ contexts: - include: php-single-quoted-strings - include: php-string-single-quoted-escapes + main: + - meta_prepend: true + # prevent stray bracket highlighting + - match: \) + scope: punctuation.section.group.end.sql + php-string-single-quoted-escapes: - match: \\[\\'] scope: constant.character.escape.php diff --git a/PHP/PHP Source.sublime-syntax b/PHP/PHP Source.sublime-syntax index dbf7e3ddca..9f6a09268c 100644 --- a/PHP/PHP Source.sublime-syntax +++ b/PHP/PHP Source.sublime-syntax @@ -1811,6 +1811,24 @@ contexts: - match: (?=\${{identifier_start}}) push: interpolation-literal-variable + interpolation: + # PHP variable/expressions interpolated into foreign + # source code without clearing any string scopes. + # + # Prevents: "c:\{$foo}" + - match: \\\{ + # Handles: "foo{$bar}baz" + - match: \{(?=\$) + scope: punctuation.section.interpolation.begin.php + set: interpolation-braced-expression + # Handles: "foo${bar}baz" + - match: \$\{ + scope: punctuation.definition.variable.begin.php + set: interpolation-braced-variable + # Handles: $foo, $foo[0], $foo[$bar], $foo->bar + - match: (?=\${{identifier_start}}) + set: interpolation-literal-variable + interpolation-braced-expression: - meta_include_prototype: false - meta_scope: meta.interpolation.php diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index 1c33997725..4be7bb5315 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -5191,21 +5191,21 @@ function testTypeCasts() // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.double.php // ^ meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string -// ^^^^^^ keyword.other.create.sql +// ^^^^^^ keyword.other.ddl.sql $sql = " CREATE TABLE `version`... // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.double.php -// ^^^^^^ keyword.other.create.sql +// ^^^^^^ keyword.other.ddl.sql "; // Do not highlight plain SQL indicator as SQL $sql = "SELECT"; -// ^^^^^^ - keyword.other.DML +// ^^^^^^ - keyword.other.dml $sql = " SELECT -// ^^^^^^ keyword.other.DML +// ^^^^^^ keyword.other.dml * FROM users WHERE first_name = 'Eric' @@ -5214,7 +5214,7 @@ function testTypeCasts() $sql = "SELECT * FROM users WHERE first_name = 'Eric'"; // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.double.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^^^^^ string.quoted.single.sql // ^ meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -5222,26 +5222,38 @@ function testTypeCasts() $sql = "SELECT * FROM users WHERE first_name = 'Eric"; // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.double.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^^^^ string.quoted.single.sql // ^ meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string $sql = " SELECT * FROM users WHERE first_name = 'Eric' //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.double.php -// ^ keyword.other.DML +// ^ keyword.other.dml +// ^^^^^ keyword.other.dml.sql // ^^^^^^ string.quoted.single.sql "; // <- meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string +$sql = "SELECT `$col` FROM 'my$table--name'"; +// ^^^^^^ meta.column-name.sql +// ^ punctuation.definition.identifier.begin.sql +// ^^^^ meta.interpolation.php variable.other.php +// ^ punctuation.definition.identifier.end.sql +// ^^^^ keyword.other.dml.sql +// ^^^^^^^^^^^^^^^^ meta.table-name.sql +// ^ punctuation.definition.identifier.begin.sql +// ^^^^^^ meta.interpolation.php variable.other.php +// ^ punctuation.definition.identifier.end.sql + $sql = "SELECT * FROM users where first_name = $user_name"; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation -// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string.quoted.double // ^ meta.string.php - meta.interpolation $sql = "SELECT * FROM users where first_name = '$user_name'"; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation -// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string.quoted // ^ meta.string.php - meta.interpolation $sql = "SELECT * FROM users where first_name = `$user_name`"; @@ -5270,22 +5282,12 @@ function testTypeCasts() // ^ meta.string.php - meta.interpolation // ^^^^^^^^^^ - meta.string // ^ meta.string.php - meta.interpolation -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php -// ^ meta.string.php - meta.interpolation -// ^^^^^^^^^^^ - meta.string -// ^ meta.string.php - meta.interpolation -// ^ meta.string.php source.sql.embedded.php -// ^ meta.string.php - meta.interpolation -// ^^^^^ - meta.string -// ^^^^^^^^^^ meta.string.php string.quoted.double.php - meta.interpolation -// ^ string.quoted.double.php punctuation.definition.string.begin.php -// ^^^^^^ keyword.other.DML.sql -// ^ string.quoted.double.php punctuation.definition.string.end.php -// ^ keyword.operator.concatenation.php -// ^^^^ variable.other.php -// ^ keyword.operator.concatenation.php -// ^ string.quoted.double.php punctuation.definition.string.begin.php -// ^^^^^^ variable.other.php +// ^^^^^ meta.string.php source.sql.embedded.php - meta.interpolation +// ^^^^^^ meta.string.php source.sql.embedded.php meta.table-name.sql meta.interpolation.php +// ^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - meta.interpolation +// ^ punctuation.section.group.begin.sql +// ^^^^^^^^^^ meta.column-name.sql - variable +// ^ keyword.operator.comparison.sql // ^ string.quoted.double.php punctuation.definition.string.end.php // ^ keyword.operator.concatenation.php // ^^^^^ variable.other.php @@ -5331,7 +5333,7 @@ function testTypeCasts() $sql = 'SELECT * FROM users WHERE first_name = \'Eric\''; // ^ meta.string.php string.quoted.single.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.single.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^^^^^^^ meta.string.sql string.quoted.single.sql // ^^ constant.character.escape.php // ^^ constant.character.escape.php @@ -5340,7 +5342,7 @@ function testTypeCasts() $sql = ' SELECT * FROM users WHERE first_name = \'Eric\' //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.single.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^ constant.character.escape.php '; // <- meta.string.php string.quoted.single.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -5360,7 +5362,7 @@ function testTypeCasts() // ^^^^^ - meta.string // ^^^^^^^^^^ meta.string.php string.quoted.single.php - meta.interpolation // ^ string.quoted.single.php punctuation.definition.string.begin.php -// ^^^^^^ keyword.other.DML.sql +// ^^^^^^ keyword.other.dml.sql // ^ string.quoted.single.php punctuation.definition.string.end.php // ^ keyword.operator.concatenation.php // ^^^^ variable.other.php @@ -5557,7 +5559,7 @@ function testTypeCasts() // ^^^ entity.name.tag.heredoc SELECT * FROM users WHERE first_name = 'John' LIMIT $limit //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.sql source.sql.embedded.php -// <- keyword.other.DML +// <- keyword.other.dml // ^ constant.other.wildcard.asterisk // ^^^^^^ string.quoted.single // ^^^^^^ variable.other.php @@ -5574,7 +5576,7 @@ function testTypeCasts() // ^^^ entity.name.tag.heredoc SELECT * FROM users WHERE first_name = 'John'\n //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.sql source.sql.embedded.php -// <- keyword.other.DML +// <- keyword.other.dml // ^ constant.other.wildcard.asterisk // ^^^^^^ string.quoted.single // ^^ - constant.character.escape.php diff --git a/Python/tests/syntax_test_python_strings.py b/Python/tests/syntax_test_python_strings.py index 4a2c02d3a2..5465042a6f 100644 --- a/Python/tests/syntax_test_python_strings.py +++ b/Python/tests/syntax_test_python_strings.py @@ -30,29 +30,29 @@ # ^^ invalid.deprecated.character.escape.python conn.execute("SELECT * FROM foobar") -# ^ meta.string.python keyword.other.DML.sql +# ^ meta.string.python keyword.other.dml.sql conn.execute('SELECT * FROM foobar') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(U"SELECT * FROM foobar") # ^ meta.string.python string.quoted.double.python punctuation.definition.string.begin.python # ^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql # ^ meta.string.python string.quoted.double.python punctuation.definition.string.end.python -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(U'SELECT * FROM foobar') # ^ meta.string.python string.quoted.single.python punctuation.definition.string.begin.python # ^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql # ^ meta.string.python string.quoted.single.python punctuation.definition.string.end.python -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # In this example, the Python string is not raw, so \t is a python escape conn.execute(u"SELECT * FROM foobar WHERE foo = '\t'") # ^ storage.type.string.python # ^ meta.string.python string.quoted.double.python punctuation.definition.string.begin.python # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.character.escape.python # ^ meta.string.python string.quoted.double.python punctuation.definition.string.end.python @@ -60,44 +60,44 @@ # ^ meta.string.python string.quoted.single.python punctuation.definition.string.begin.python # ^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql # ^ meta.string.python string.quoted.single.python punctuation.definition.string.end.python -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # In this example, the Python string is raw, so the \b should be a SQL escape conn.execute(r"SELECT * FROM foobar WHERE baz = '\b") -# ^ meta.string.python keyword.other.DML.sql +# ^ meta.string.python keyword.other.dml.sql # ^ constant.character.escape.sql # This tests to ensure the Python placeholder will be highlighted even in a raw SQL string conn.execute(r'SELECT * FROM foobar WHERE %s') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.other.placeholder.python conn.execute(r"SELECT * FROM foobar") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(r'SELECT * FROM foobar') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(r"""SELECT * FROM foobar WHERE %s and foo = '\t'""") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.other.placeholder.python # ^ constant.character.escape.sql # Capital R prevents all syntax embedding conn.execute(R'SELECT * FROM foobar') -# ^ meta.string.python - keyword.other.DML.sql +# ^ meta.string.python - keyword.other.dml.sql conn.execute(R"SELECT * FROM foobar") -# ^ - keyword.other.DML.sql +# ^ - keyword.other.dml.sql conn.execute(R"""SELECT * FROM foobar""") -# ^ - keyword.other.DML.sql +# ^ - keyword.other.dml.sql conn.execute(r'''SELECT * FROM foobar''') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(u"""SELECT * FROM foobar WHERE %s and foo = '\t'""") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.other.placeholder.python # ^ constant.character.escape.python @@ -211,7 +211,7 @@ EXISTS( select 1) ELSE NULL - ) as result + END) as result """ + test # ^^^ meta.string.python string.quoted.double.block.python punctuation.definition.string.end.python # ^ keyword.operator.arithmetic.python @@ -229,7 +229,7 @@ EXISTS( select 1) ELSE NULL - ) as result + END) as result """ query = \ @@ -243,7 +243,7 @@ EXISTS( select 1) ELSE NULL - ) as result + END) as result ''' query = """ @@ -914,6 +914,9 @@ COMMIT;" # ^^^^^^ meta.string.python source.sql - string +sql = "DELETE FROM HumanResources.JobCandidate WHERE JobCandidateID = 13;" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql - string.quoted + sql = Ur"SELECT `name` FROM `users` \ WHERE `password` LIKE 'abc'" #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql - string.quoted.double diff --git a/Rails/SQL (Rails).sublime-syntax b/Rails/SQL (Rails).sublime-syntax index 5a10f58090..5a49301d62 100644 --- a/Rails/SQL (Rails).sublime-syntax +++ b/Rails/SQL (Rails).sublime-syntax @@ -2,6 +2,7 @@ --- name: SQL (Rails) scope: source.sql.rails +version: 2 extends: Packages/SQL/SQL.sublime-syntax diff --git a/Ruby/Embeddings/SQL (for Ruby).sublime-syntax b/Ruby/Embeddings/SQL (for Ruby).sublime-syntax index dac679e014..a81d06ecc2 100644 --- a/Ruby/Embeddings/SQL (for Ruby).sublime-syntax +++ b/Ruby/Embeddings/SQL (for Ruby).sublime-syntax @@ -1,7 +1,7 @@ %YAML 1.2 --- scope: source.sql.embedded.ruby -# version: 2 +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax new file mode 100644 index 0000000000..01aa50387e --- /dev/null +++ b/SQL/Cassandra.sublime-syntax @@ -0,0 +1,242 @@ +%YAML 1.2 +--- +# https://cassandra.apache.org/doc/latest/cassandra/cql/ +name: Cassandra Query Language +scope: source.sql.cql +version: 2 + +extends: Packages/SQL/SQL (basic).sublime-syntax + +file_extensions: + - cql + +variables: + + ddl_target_function: |- + (?xi: function ) + + ddl_target_other: |- + (?xi: keyspace | type | user | (?: materialized \s+ )? view ) + + simple_types: |- + (?xi: + ASCII | BIGINT | BLOB | BOOLEAN | COUNTER | DATE | DECIMAL | DOUBLE + | DURATION | FLOAT | INET | INT | SMALLINT | TEXT | TIME | TIMESTAMP + | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT ) + + types_with_optional_number: (?!) + +contexts: + +###[ DDL CREATE STATEMENTS ]################################################### + + create-target: + - meta_prepend: true + - include: create-type + + create-type: + - match: \b(?i:type)\b + scope: keyword.other.ddl.cql + push: + - create-type-args + - maybe-column-declaration-list + - expect-type-creation-name + - create-type-condition + + create-type-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-type-args: + - meta_scope: meta.type.sql + - include: create-common-args + + create-common-args: + - meta_prepend: true + - match: \b(?i:clustering)\b + scope: keyword.other.cql + - match: \b(?i:with)\b + scope: keyword.other.cql + +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - meta_prepend: true + - match: \b(?i:(select)\s+(json))\b + captures: + 1: keyword.other.dml.sql + 2: storage.modifier.cql + - match: \b(?i:allow\s+filtering)\b + scope: keyword.other.dml.cql + - match: \b(?i:copy)\b + scope: keyword.other.dml.cql + push: + - dml-copy-from + - maybe-group + - expect-table-name + + dml-copy-from: + - match: \b(?i:from)\b + scope: keyword.other.cql + pop: 1 + - include: else-pop + + join-expressions: [] + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: + - meta_prepend: true + - match: \b(?i:use)\b + scope: keyword.context.sql + push: expect-database-name + - match: \b(?i:source)\b + scope: keyword.other.cql + +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_append: true + - include: arrays + - include: dicts-or-sets + - match: \b(?i:limit)\b + scope: keyword.other.dml.cql + - match: \b((?i:with))\s+(\w+)? + captures: + 1: keyword.other.cql + 2: string.unquoted.cql + - match: \b(?i:primary\s+key)\b + scope: storage.modifier.cql + - match: \b(?i:using\s+ttl)\b + scope: keyword.other.cql + + built-in-scalar-function-calls: + - meta_append: true + - match: \b(?:token|uuid|now|toJson|TTL|WRITETIME|KEYS|ENTRIES|FULL)(?=\s*\() + scope: support.function.scalar.cql + push: function-call-arguments + + arrays: + - match: \[ + scope: punctuation.section.brackets.begin.cql + push: inside-array + + inside-array: + - meta_scope: meta.brackets.cql + - match: \] + scope: punctuation.section.brackets.end.cql + pop: 1 + - include: expressions + + dicts-or-sets: + - match: \{ + scope: punctuation.section.braces.begin.cql + push: inside-dict-or-set + + inside-dict-or-set: + - meta_scope: meta.braces.cql + - match: \} + scope: punctuation.section.braces.end.cql + pop: 1 + - match: ':' + scope: punctuation.separator.key-value.cql + - include: expressions + - match: '{{simple_identifier}}' + scope: meta.mapping.key.cql string.unquoted.cql + +###[ COLUMN EXPRESSIONS ]###################################################### + + inside-column-declaration-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:(primary\s+key))\s*(\() + captures: + 1: storage.modifier.cql + 2: meta.group.partition-key.cql punctuation.section.group.begin.cql + push: inside-partition-key + - match: \b(?i:primary\s+key)\b + scope: storage.modifier.cql + - include: expressions + - include: expect-column-declarations + + inside-partition-key: + - meta_content_scope: meta.group.partition-key.cql + - match: \) + scope: meta.group.partition-key.cql punctuation.section.group.end.cql + pop: 1 + - match: \( + scope: punctuation.section.group.begin.cql + push: inside-partition-key-group + - match: ',' + scope: punctuation.separator.sequence.cql + set: inside-group + - include: expect-column-names + + inside-partition-key-group: + - match: \) + scope: punctuation.section.group.end.cql + pop: 1 + - match: ',' + scope: punctuation.separator.sequence.cql + - include: expect-column-names + +###[ TYPES ]################################################################### + + built-in-type: + - meta_prepend: true + # https://cassandra.apache.org/doc/latest/cassandra/cql/types.html#collections + - match: \b(?i:frozen|list|map|set|tuple)\b + scope: storage.type.cql + set: maybe-generic + + maybe-generic: + - match: < + scope: punctuation.definition.generic.begin.cql + set: + - inside-generic + - expect-generic-type + - include: else-pop + + inside-generic: + - meta_scope: meta.generic.cql + - match: \> + scope: punctuation.definition.generic.end.cql + pop: 1 + - match: ',' + scope: punctuation.separator.sequence.cql + push: expect-generic-type + + expect-generic-type: + - match: (?=[,>]) + pop: 1 + - include: expect-type + +###[ LITERALS ]################################################################ + + constants: + - meta_prepend: true + - include: booleans + + literals-and-variables: + - meta_prepend: true + - include: variables + + numbers: + - meta_prepend: true + - match: \h{8}(?:-\h{4}){3}-\h{12} + scope: constant.numeric.uuid.cql + + variables: + - match: (:){{simple_identifier}} + scope: variable.other.constant.cql + captures: + 1: punctuation.definition.variable.cql + +###[ OPERATORS ]############################################################### + + logical-operators: + - meta_append: true + - match: \b(?i:contains(?:\s+key)?)\b + scope: keyword.operator.logical.cql diff --git a/SQL/Indentation Rules - Comments.tmPreferences b/SQL/Indentation Rules - Comments.tmPreferences new file mode 100644 index 0000000000..e018720e72 --- /dev/null +++ b/SQL/Indentation Rules - Comments.tmPreferences @@ -0,0 +1,12 @@ + + + + scope + source.sql comment + settings + + preserveIndent + + + + diff --git a/SQL/Indentation Rules.tmPreferences b/SQL/Indentation Rules.tmPreferences index 8bc06e9e1e..941f81f112 100644 --- a/SQL/Indentation Rules.tmPreferences +++ b/SQL/Indentation Rules.tmPreferences @@ -2,13 +2,27 @@ scope - source.sql + source.sql - string - comment settings decreaseIndentPattern - \)(?!=.*\() + (?xi) + \)(?!=.*\() + |^\s*end\b + increaseIndentPattern - ^\s*(create|grant|insert|delete|update)\b|\((?!.*\)) + (?xi) + ^\s* + (?: + (?:create|grant|delete|update|begin)\b + #| select\s*$ + ) + |\((?!.*\)) + + unIndentedLinePattern + (?xi) + ^go$ + diff --git a/SQL/Indexed Symbol List.tmPreferences b/SQL/Indexed Symbol List.tmPreferences new file mode 100644 index 0000000000..7421686520 --- /dev/null +++ b/SQL/Indexed Symbol List.tmPreferences @@ -0,0 +1,12 @@ + + + + scope + source.sql entity.name.struct + settings + + showInIndexedSymbolList + 1 + + + diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax new file mode 100644 index 0000000000..3bd6ebcbda --- /dev/null +++ b/SQL/MySQL.sublime-syntax @@ -0,0 +1,1694 @@ +%YAML 1.2 +--- +name: MySQL +scope: source.sql.mysql +version: 2 + +extends: Packages/SQL/SQL (basic).sublime-syntax + +variables: + additional_toplevel_reserved: |- + (?xi: {{conditional_keywords}} | {{flow_keywords}} | {{loop_keywords}} + | begin | end | rename | show ) + + conditional_keywords: |- + (?xi: if | end\s+if | else(?:if)? | then ) + + flow_keywords: |- + (?xi: continue | exit | return ) + + loop_keywords: |- + (?xi: loop | end\s+(?: loop | repeat | while ) | repeat | while ) + + other_keywords: |- + (?xi: close | cursor | declare | deallocate | delimiter | execute | fetch + | for | found | open | prepare | with ) + + function_parameter_modifier: |- + (?xi: in\s*out | in | out ) + + database_parameters: |- + (?xi: (?:default\s+)? (?: char(?:acter\s+)?set | collate ) ) + + partition_parameters: |- + (?xi: (?:storage\s+)?engine | (?:data|index)\s+directory | max_rows | min_rows | nodegroup ) + + table_parameters: |- + (?xi: (?:storage\s+)?engine | (?:default\s+)?(?: char(?:acter\s+)?set | collate ) + | auto_increment | avg_row_length | checksum | connection | data\s+directory + | delay_key_write | encrypted | encryption_key_id | ietf_quotes | index\s+directory + | insert_method | key_block_size | max_rows | min_rows | pack_keys | page_checksum + | page_compressed | page_compression_level | password | row_format | sequence + | stats_auto_recalc | stats_persistent | stats_sample_pages | transactional ) + table_row_formats: |- + (?xi: dynamic | fixed | compressed | redundant | compact | page ) + + # https://mariadb.com/kb/en/data-types + simple_types: |- + (?xi: boolean | bool | uuid | year ) + + types_with_optional_number: |- + (?xi: + # numeric data types + (?: big | medium | middle | small | tiny ) int + | bit(?: \s+ varying )? + | date(?: time )? + | dec(?: imal )? + | double(?: \s+ precision )? + | fixed + | float[48]? + | int(?: [12348] | eger )? + | number + | numeric + | real + | (?: local )?time(?: stamp )? + # string data types + | (?: long | medium | tiny )? (?: blob | text ) + | binary (?: \s+ varying )? + | char \s+ byte + | (?: national \s+ )? char(?: acter )? (?: \s+ varying )? + | inet[46] + | long(?: \s+ varchar )? + | var(?: binary | char (?: acter )? ) + ) + + time_units: |- + (?xi: year(?: _month )? | day(?: _hour | _minute | _second | _microsecond )? + | hour(?: _minute | _second | _microsecond )? | minute(?: _second | _microsecond )? + | second(?: _microsecond )? | quarter | month | week ) + + builtin_constants: |- + (?xi: all | default | maxvalue + # index algorithm/lock values + | inplace | copy | nocopy | instant | exclusive | shared + | system\s+versioning ) + + builtin_user_functions: |- + (?xi: (?: current | session | system )_(?: role | user )) + +contexts: + sql: + - meta_append: true + - include: regexps + + statements: + - meta_prepend: true + - include: rename-statements + - include: show-statements + +###[ COMMENTS ]################################################################ + + comments: + - meta_append: true + - include: number-sign-comments + + double-dash-comments: + - match: '--(?=\s)' + scope: punctuation.definition.comment.sql + push: inside-double-dash-comment + + number-sign-comments: + - match: '#' + scope: punctuation.definition.comment.sql + push: inside-number-sign-comment + + inside-number-sign-comment: + - meta_include_prototype: false + - meta_scope: comment.line.number-sign.sql + - match: \n + pop: 1 + +###[ DDL CREATE STATEMENTS ]################################################### + + create-statements: + - meta_prepend: true + - match: \b(?i:create\s+or\s+replace)\b + scope: keyword.other.ddl.sql + push: + - create-meta + - create-target + + create-target: + - meta_prepend: true + - include: algorithms + - include: definers + - include: create-database + - include: create-event + - include: create-role + - include: create-user + + create-database: + # https://mariadb.com/kb/en/create-database + - match: \b(?i:database|schema)\b + scope: keyword.other.ddl.sql + set: + - create-database-args + - expect-database-creation-name + - create-database-condition + + create-database-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-database-args: + - meta_scope: meta.database.sql + - match: \b{{database_parameters}}\b + scope: variable.parameter.database.sql + - include: assignment-operators-constants + - include: comment-keywords + - include: strings + - include: else-pop + + create-event: + # https://mariadb.com/kb/en/create-event + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: + - create-event-args + - expect-event-creation-name + - create-event-condition + + create-event-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-event-args: + - meta_scope: meta.event.sql + - include: event-options + - include: pop-on-top-level-reserved-word + + create-index-args: + # https://mariadb.com/kb/en/create-index + - meta_prepend: true + - include: index-algorithm-args + - include: index-clustering-args + - include: index-lock-args + - include: index-parser-args + - include: index-type-args + - include: index-wait-args + - include: index-other-args + - include: comment-keywords + + create-role: + # https://mariadb.com/kb/en/create-role + - match: \b(?i:role)\b + scope: keyword.other.ddl.sql + set: + - create-role-args + - expect-user-name-declaration + - create-role-condition + + create-role-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-role-args: + - meta_scope: meta.user.sql + - include: maybe-with-admin-user + + create-table-args: + # https://mariadb.com/kb/en/create-table + - meta_prepend: true + - include: partition-declaration-lists + - include: partition-options + - include: table-options + + create-user: + # https://mariadb.com/kb/en/create-user + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: + - create-user-args + - create-user-name-list + - user-identification + - expect-user-name-declaration + - create-user-condition + + create-user-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-user-name-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-identification + - expect-user-name-declaration + - include: else-pop + + create-user-args: + - meta_scope: meta.user.sql + - include: user-options + + create-other-args: + - meta_prepend: true + - match: (?=\() + push: column-declaration-list + +###[ DDL DROP STATEMENTS ]##################################################### + + drop-target: + - meta_prepend: true + - include: algorithms + - include: drop-database + - include: drop-event + - include: drop-user + + drop-database: + # https://mariadb.com/kb/en/drop-database + - match: \b(?i:database|schema)\b + scope: keyword.other.ddl.sql + set: + - drop-database-args + - expect-database-name + - drop-database-condition + + drop-database-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-database-args: + - meta_include_prototype: false + - meta_scope: meta.database.sql + - include: immediately-pop + + drop-event: + # https://mariadb.com/kb/en/drop-event + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: + - drop-event-args + - expect-event-name + - drop-event-condition + + drop-event-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-event-args: + - meta_include_prototype: false + - meta_scope: meta.event.sql + - include: immediately-pop + + drop-index-args: + - meta_prepend: true + - include: index-wait-args + + drop-user: + # https://mariadb.com/kb/en/drop-role + # https://mariadb.com/kb/en/drop-user + - match: \b(?i:role|user)\b + scope: keyword.other.ddl.sql + set: + - drop-user-args + - expect-user-name + - drop-user-condition + + drop-user-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-user-args: + - meta_scope: meta.user.sql + - include: user-name-list + +###[ DDL ALTER STATEMENTS ]#################################################### + + alter-target: + - meta_prepend: true + - include: algorithms + - include: definers + - include: alter-database + - include: alter-event + - include: alter-user + +###[ DDL ALTER COLUMNS STATEMENTS ]############################################ + + alter-columns: + - meta_prepend: true + - match: \b(?i:(change)\s+(column))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - expect-type + - expect-column-name-declaration + - expect-column-name + +###[ DDL ALTER DATABASE STATEMENTS ]########################################### + + alter-database: + # https://mariadb.com/kb/en/alter-database + - match: \b(?i:database|schema)\b + scope: keyword.other.ddl.sql + set: + - alter-database-args + - expect-database-name + - alter-database-condition + + alter-database-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-database-args: + - meta_scope: meta.database.sql + - match: \b(?i:(upgrade)(?:\s+(data\s+directory\s+name))?)\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + pop: 1 + - include: create-database-args + +###[ DDL ALTER EVENT STATEMENTS ]############################################## + + alter-event: + # https://mariadb.com/kb/en/alter-event + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: + - alter-event-args + - expect-event-name + - alter-event-condition + + alter-event-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-event-args: + - meta_scope: meta.event.sql + - include: event-options + - include: pop-on-top-level-reserved-word + +###[ DDL ALTER TABLE STATEMENTS ]############################################## + + alter-table: + - meta_prepend: true + - match: \b(?i:online|ignore)\b + scope: keyword.other.ddl.sql + + alter-table-args: + - match: \b(?i:add)\b + scope: keyword.other.ddl.sql + push: alter-table-add-target + - match: \b(?i:change)\b + scope: keyword.other.ddl.sql + push: alter-table-change-target + - match: \b(?i:drop)\b + scope: keyword.other.ddl.sql + push: alter-table-drop-target + - match: \b(?i:modify)\b + scope: keyword.other.ddl.sql + push: alter-table-modify-target + - match: \b(?i:rename)\b + scope: keyword.other.ddl.sql + push: alter-table-rename-target + # drop args + - match: \b(?i:cascade|restrict)\b + scope: keyword.other.ddl.sql + # partition commands + - match: \b(?i:check)\b + scope: keyword.other.sql + # table options + - include: index-wait-args + - include: partition-options + - include: table-options + # expressions + - include: pop-on-top-level-reserved-word + - include: literals-and-variables + - include: comma-separators + - include: operators + + alter-table-add-target: + - include: system-versioning + - include: alter-table-add-index + - include: alter-table-add-partition + - include: alter-table-add-period + - include: alter-table-add-column # must be the last one + + alter-table-add-column: + - match: (?=\S) + set: + - maybe-column-position + - expect-column-declaration + - maybe-condition + - maybe-column + + alter-table-add-index: + - match: \b(?i:constraint)\b + scope: keyword.other.ddl.sql + push: + - maybe-check + - expect-constraint-name + - match: \b(?i:(primary)\s+(key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: alter-table-add-index-args + - match: \b(?i:(?:(foreign|fulltext|spatial|unique)\s+)?(index|key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - alter-table-add-index-args + - expect-index-name + - maybe-condition + + alter-table-add-index-args: + - include: column-name-lists + - include: comment-keywords + - include: index-algorithm-args + - include: index-clustering-args + - include: index-lock-args + - include: index-parser-args + - include: index-type-args + - include: index-other-args + - include: literals-and-variables + - include: operators + - include: else-pop + + alter-table-add-partition: + - match: \b(?i:partition)\b + scope: keyword.other.ddl.sql + set: + - maybe-partition-declaration-list + - maybe-condition + + alter-table-add-period: + - match: \b(?i:(period)\s+(for)\s+(system_time))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + set: maybe-column-name-list + + alter-table-change-target: + - include: alter-table-change-column + + alter-table-change-column: + - match: (?=\S) + set: + - after-type + - expect-type + - expect-column-name-declaration + - expect-column-name + - maybe-condition + - maybe-column + + alter-table-drop-target: + - include: system-versioning + - include: alter-table-drop-constraint + - include: alter-table-drop-index + - include: alter-table-drop-partition + - include: alter-table-drop-column # must be the last one + + alter-table-drop-column: + - match: (?=\S) + set: + - expect-column-name + - maybe-condition + - maybe-column + + alter-table-drop-constraint: + - match: \b(?i:constraint)\b + scope: keyword.other.ddl.sql + set: + - expect-constraint-name + - maybe-condition + + alter-table-drop-index: + - match: \b(?i:primary\s+key)\b + scope: keyword.other.ddl.sql + pop: 1 + - match: \b(?i:index|(?:foreign\s+)?key)\b + scope: keyword.other.ddl.sql + set: + - expect-index-name + - maybe-condition + + alter-table-drop-partition: + - match: \b(?i:partition)\b + scope: keyword.other.ddl.sql + set: + - expect-partition-name + - maybe-condition + + alter-table-modify-target: + - include: alter-table-modify-column + + alter-table-modify-column: + - match: (?=\S) + set: + - after-type + - expect-type + - expect-column-name-declaration + - maybe-condition + - maybe-column + + alter-table-rename-target: + - include: alter-table-rename-column + - include: alter-table-rename-index + - include: alter-table-rename-table # must be the last one + + alter-table-rename-column: + - match: \b(?i:column)\b + scope: keyword.other.ddl.sql + set: + - expect-column-name + - maybe-to + - expect-column-name + + alter-table-rename-index: + - match: \b(?i:index|key)\b + scope: keyword.other.ddl.sql + set: + - expect-index-name + - maybe-to + - expect-index-name + + alter-table-rename-table: + - match: (?=\S) + set: + - expect-table-name + - maybe-to + +###[ DDL ALTER USER STATEMENTS ]############################################### + + alter-user: + # https://mariadb.com/kb/en/alter-user + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: + - alter-user-args + - expect-user-identification-list + - user-identification + - expect-user-name + - alter-user-condition + + alter-user-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-user-args: + - meta_scope: meta.user.sql + - include: user-options + +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - meta_append: true + - include: index-hint-lists + - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b + scope: keyword.other.dml.sql + push: expect-table-name + - match: \b(?i:limit)\b + scope: keyword.other.dml.sql + - match: \b(?i:on\s+duplicate\s+key)\b + scope: keyword.other.dml.sql + + join-expressions: + # https://mariadb.com/kb/en/join-syntax + - match: \b(?i:(?:(?:cross|inner|(?:natural\s+)?(?:left|right)(?:\s+outer)?)\s+|straight_)?join)\b + scope: keyword.other.dml.sql + push: + - join-condition + - table-name-or-subquery + + join-condition: + - meta_prepend: true + - match: \b(?i:using)\b + scope: keyword.other.dml.sql + set: maybe-column-name-list + +###[ DML SET STATEMENTS ]###################################################### + + set-target: + - meta_prepend: true + - include: set-password + - include: set-role + + set-password: + # https://mariadb.com/kb/en/set-password + - match: \b(?i:password)\b + scope: keyword.other.dml.sql + set: + - set-other-assignment + - maybe-for-user + + set-role: + # https://mariadb.com/kb/en/set-role + # https://mariadb.com/kb/en/set-default-role + - match: \b(?i:(?:(default)\s+)?(role))\b + captures: + 1: keyword.other.dml.sql + 2: keyword.other.dml.sql + set: + - maybe-for-user + - set-role-name + + set-role-name: + - include: none-constant + - include: expect-user-name + + set-other-assignment: + - match: = + scope: keyword.operator.assignment.sql + set: set-other-value + - include: else-pop + + set-other-value: + - include: expressions + - include: pop-on-top-level-reserved-word + +###[ GRANT STATEMENTS ]######################################################## + + grant-statements: + # https://mariadb.com/kb/en/grant + - match: \b(?i:grant)\b + scope: keyword.other.authorization.sql + push: + - grant-meta + - grant-options + - grant-to-user + - grant-target + + grant-target: + # grant proxy on name to user + - match: \b(?i:proxy)\b + scope: keyword.other.ddl.sql + set: grant-on-user + # grant role name to + - match: (?=\S+\s+(?i:to)\b) + set: expect-user-name + # grant operation on + - match: (?=\S) + set: grant-operations + + grant-operations: + - match: (?=[;)]|\b(?i:grant|to|with)\b) + pop: 1 + - include: on-privilidge-level + - include: comma-separators + - include: user-privileges + + grant-on-user: + - match: \b(?i:on)\b + scope: keyword.context.sql + - include: expect-user-name + + grant-to-user: + - match: \b(?i:to)\b + scope: keyword.context.sql + - include: expect-user-identification-list + + grant-options: + - include: user-grant-privileges + - include: user-resource-options + - include: else-pop + +###[ RENAME STATEMENTS ]####################################################### + + rename-statements: + # https://mariadb.com/kb/en/rename-user + - match: \b(?i:rename)\b + scope: keyword.other.authorization.sql + push: + - rename-meta + - rename-target + + rename-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.rename.sql + - include: immediately-pop + + rename-target: + - match: \b(?i:user)\b + scope: keyword.other.authorization.sql + set: + - rename-user + - expect-user-name + - include: else-pop + + rename-user: + - match: \b(?i:to)\b + scope: keyword.context.sql + push: expect-user-name + - include: user-name-list + +###[ REVOKE STATEMENTS ]####################################################### + + revoke-statements: + # https://mariadb.com/kb/en/revoke + - match: \b(?i:revoke)\b + scope: keyword.other.authorization.sql + push: + - revoke-meta + - revoke-options + - revoke-privileges + + revoke-privileges: + - match: (?=[;)]|\b(?i:for|from)\b) + pop: 1 + - include: on-privilidge-level + - include: comma-separators + - include: user-privileges + + revoke-options: + - match: \b(?i:for|from)\b + scope: keyword.context.sql + push: + - user-name-list + - expect-user-name + - include: else-pop + +###[ SHOW STATEMENTS ]######################################################### + + show-statements: + - match: \b(?i:show|describe)\b + scope: keyword.other.dml.sql + push: + - show-meta + - show-target + - match: \b(?i:explain(?:\s+analyze)?)\b + scope: keyword.other.dml.sql + push: explain-parameters + + show-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.show.sql + - include: immediately-pop + + show-target: + - include: show-create + - include: show-grants + - include: show-columns + - include: else-pop + + show-create: + - match: \b(?i:create)\b + scope: keyword.other.ddl.sql + set: show-create-target + + show-create-target: + - include: show-create-event + - include: show-create-user + - include: show-create-other + - include: else-pop + + show-create-event: + # https://mariadb.com/kb/en/show-create-event + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: expect-event-name + + show-create-user: + # https://mariadb.com/kb/en/show-create-user + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: expect-user-name + + show-create-other: + - match: '{{simple_identifier}}' + scope: keyword.other.ddl.sql + set: expect-other-name + + show-grants: + # https://mariadb.com/kb/en/show-grants + - match: \b(?i:grants)\b + scope: keyword.other.dml.sql + set: maybe-for-user + + show-columns: + - match: \b(?i:full|extended)\b + scope: keyword.other.mysql + - match: \b(?i:columns|fields)\b + scope: keyword.other.mysql + - match: \b(?i:from|in)\b + scope: keyword.other.mysql + set: expect-table-name + + explain-parameters: + - match: \b(?i:format)\b + scope: variable.parameter.explain.sql + - include: assignment-operators-constants + - match: \b(?i:into)\b + scope: keyword.other.dml.sql + push: expect-table-name + - match: \b(?i:for\s+schema)\b + scope: keyword.other.dml.sql + push: expect-other-name + - include: else-pop + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: + - match: \b{{conditional_keywords}}\b + scope: keyword.control.conditional.sql + - match: \b{{loop_keywords}}\b + scope: keyword.control.loop.sql + - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b + scope: keyword.other.luw.sql + - match: \b(?i:end)\b + scope: keyword.control.flow.end.sql + - match: \b(?i:continue)\b + scope: keyword.control.flow.continue.sql + - match: \b(?i:exit)\b + scope: keyword.control.flow.exit.sql + - match: \b(?i:return)\b + scope: keyword.control.flow.return.sql + - match: \b(?i:(?:un)?lock\s+tables?)\b + scope: keyword.context.resource.mysql + push: + - expect-lock-type + - expect-table-name + + expect-lock-type: + - match: \b(?i:read|write)\b + scope: constant.language.lock-type.mysql + - match: ',' + scope: punctuation.separator.sequence.mysql + set: + - expect-lock-type + - expect-table-name + - include: else-pop + +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_prepend: true + - match: \b{{other_keywords}}\b + scope: keyword.other.sql + - match: \b(?i:concatenate|convert|lower|substring|translate|trim|upper)\b + scope: support.function.string.sql + - match: \b(?i:using)\b + scope: keyword.other.dml.sql + - include: like-expressions + + assignment-operators-constants: + - include: assignment-operators + - match: \b(?i:utf8|utf8mb3|tree|traditional|json)\b + scope: string.unquoted.mysql + +###[ ALGORITHM EXPRESSIONS ]################################################### + + algorithms: + - match: \b(?i:algorithm)\b + scope: keyword.other.mysql + push: algorithm-assignment + + algorithm-assignment: + - match: = + scope: keyword.operator.assignment.sql + set: algorithm-value + - include: else-pop + + algorithm-value: + - match: \b(?i:merge|temptable|undefined)\b + scope: constant.language.sql + pop: 1 + - include: else-pop + + definers: + - match: \b(?i:definer)\b + scope: variable.parameter.definer.sql + push: maybe-user-assignment + +###[ COLUMN EXPRESSIONS ]###################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:auto_increment)\b + scope: storage.modifier.sql + - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) + scope: keyword.other.object-comments.sql + +###[ EVENT EXPRESSIONS ]####################################################### + + event-options: + - match: \b(?i:do)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: comment-keywords + - include: event-schedule-args + - include: event-enable-args + - include: event-completion-args + + event-completion-args: + - match: \b(?i:(on)\s+(completion))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:preserve)\b + scope: constant.language.sql + + event-enable-args: + - match: \b(?i:(on)\s+(slave))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:enable|disable)\b + scope: keyword.other.ddl.sql + + event-schedule-args: + - match: \b(?i:(on)\s+(schedule))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:starts|ends)\b + scope: keyword.other.ddl.sql + - match: \b(?i:at)\b + scope: keyword.other.ddl.sql + - match: \b(?i:every)\b + scope: keyword.other.ddl.sql + - include: intervals + - include: expressions + +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-characteristics: + # https://mariadb.com/kb/en/create-function + - meta_prepend: true + - match: \b(?i:return)\b + scope: keyword.control.flow.return.sql + pop: 1 + - match: \b(?i:not)\b + scope: keyword.operator.logical.sql + - match: \b(?i:deterministic)\b + scope: storage.modifier.sql + - match: \b(?i:(?:contains|no)\s+sql|(?:reads|modifies)\s+sql\s+data)\b + scope: storage.modifier.sql + - match: \b(?i:sql\s+security)\b + scope: storage.modifier.sql + - match: \b(?i:definer|invoker)\b + scope: constant.language.user.sql + - match: \b(?i:soname)\b + scope: keyword.other.ddl.sql + - include: comment-keywords + +###[ INDEX EXPRESSIONS ]####################################################### + + index-algorithm-args: + - match: \b(?i:algorithm)\b + scope: keyword.other.ddl.sql + + index-clustering-args: + - match: \b(?i:clustering)\b + scope: keyword.other.ddl.sql + + index-lock-args: + - match: \b(?i:lock)\b + scope: keyword.other.ddl.sql + + index-parser-args: + - match: \b(?i:with\s+parser)\b + scope: keyword.other.ddl.sql + push: expect-other-name + + index-type-args: + - match: \b(?i:using)\b + scope: keyword.other.ddl.sql + push: index-type-value + + index-type-value: + - match: \b(?i:btree|hash|rtree)\b + scope: constant.language.sql + pop: 1 + - include: else-pop + + index-wait-args: + - match: \b(?i:nowait|wait)\b + scope: keyword.other.ddl.sql + + index-other-args: + - match: \b(?i:ignored)\b + scope: keyword.other.ddl.sql + - match: \b(?i:key_block_size)\b + scope: keyword.other.ddl.sql + +###[ PARTITION EXPRESSIONS ]################################################### + + maybe-partition-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: + - inside-partition-declaration-list + - expect-partition-creation-name + - maybe-partition + - include: else-pop + + partition-declaration-lists: + - match: \( + scope: punctuation.section.group.begin.sql + push: + - inside-partition-declaration-list + - expect-partition-creation-name + - maybe-partition + + inside-partition-declaration-list: + - meta_scope: meta.group.partitions.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + # partition and subpartition declarations + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - expect-partition-creation-name + - maybe-partition + # partition parameters + - match: \b(?i:values)\b + scope: keyword.other.ddl.sql + - match: \b(?i:in|less\s+than)\b + scope: keyword.operator.logical.sql + push: maybe-group + - match: \b{{partition_parameters}}\b + scope: variable.parameter.sql + - include: partition-declaration-lists + - include: comment-keywords + - include: tablespaces + - include: expressions + + maybe-partition: + - match: \b(?i:(?:sub)?partition)\b + scope: keyword.other.ddl.sql + - include: else-pop + + partition-options: + # partition keywords + - match: \b(?i:(?:sub)?partition by)\b + scope: keyword.other.sql + - match: \b(?i:(?:sub)?partitions)\b + scope: keyword.other.sql + # partition arguments + - match: \b(?i:linear)\b + scope: storage.modifier.sql + - match: \b(?i:hash|range|list)\b + scope: support.function.sql + push: maybe-group + - match: \b(?i:key)\b + scope: support.function.sql + push: maybe-column-name-list + - match: \b(?i:limit|system_time)\b + scope: keyword.other.sql + - include: intervals + - include: time-units + + maybe-partition-name-list: + - include: partition-name-list + - include: else-pop + + partition-name-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-partition-name-list + + inside-partition-name-list: + - meta_scope: meta.group.partitions.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - include: expect-partition-names + +###[ TABLE EXPRESSIONS ]####################################################### + + table-options: + - include: comment-keywords + # table options with special treatment + - include: tablespaces + - match: \b(?i:like)\b + scope: keyword.other.sql + push: expect-table-name + - match: \b(?i:union)\b + scope: variable.parameter.sql + push: maybe-table-name-list + - match: \b(?i:with)\b + scope: keyword.other.sql + # common table options + - match: \b{{table_parameters}}\b + scope: variable.parameter.sql + - match: \b{{table_row_formats}}\b + scope: constant.language.sql + # common table option values + - match: \b(?i:after)\b + scope: keyword.other.position.sql + push: expect-column-name + - match: \b(?i:first|last)\b + scope: keyword.other.position.sql + - match: \b(?i:system\s+versioning)\b + scope: constant.language.sql + + maybe-column-position: + - match: \b(?i:after)\b + scope: keyword.other.position.sql + set: expect-column-name + - match: \b(?i:first|last)\b + scope: keyword.other.position.sql + pop: 1 + - include: else-pop + + system-versioning: + - match: \b(?i:system\s+versioning)\b + scope: constant.language.sql + pop: 1 + + tablespaces: + - match: \b(?i:tablespace)\b + scope: variable.parameter.sql + push: maybe-tablespace-name + + maybe-tablespace-name: + - include: assignment-operators + - include: expect-other-name + + maybe-table-name-list: + - match: \( + scope: punctuation.section.sequence.begin.sql + set: inside-table-name-list + - include: assignment-operators + - include: else-pop + + inside-table-name-list: + - meta_scope: meta.sequence.tables.sql + - match: \) + scope: punctuation.section.sequence.end.sql + pop: 1 + - include: comma-separators + - include: expect-table-names + +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + maybe-with-admin-user: + - meta_scope: meta.user.sql + - match: \b(?i:with)\b + scope: keyword.other.ddl.sql + set: + - expect-user-name + - maybe-admin + - include: else-pop + + maybe-admin: + - match: \b(?i:admin)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + + maybe-for-user: + - match: \b(?i:for)\b + scope: keyword.other.dml.sql + set: expect-user-name + - include: else-pop + + maybe-user-assignment: + - match: = + scope: keyword.operator.assignment.sql + set: expect-user-name + - include: else-pop + + expect-user-identification-list: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: + - user-identification-list + - user-identification + - expect-user-name + + user-identification-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-identification + - expect-user-name + - include: else-pop + + user-identification: + - match: \b(?i:identified|by)\b + scope: keyword.other.ddl.sql + - match: \b(?i:password)\b + scope: storage.modifier.sql + - match: \b(?i:via)\b + scope: keyword.other.ddl.sql + set: + - user-auth-list + - user-auth-args + - expect-other-name + - include: strings + - include: else-pop + + user-name-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: expect-user-name + - include: else-pop + + user-auth-list: + # used by CREATE/ALTER user + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-auth-args + - expect-other-name + # used by GRANT statements + - match: \b(?i:or)\b + scope: keyword.operator.logical.sql + push: + - user-auth-args + - expect-other-name + - include: else-pop + + user-auth-args: + - match: (?=,|\b(?i:account|on|or|require|with)\b) + pop: 1 + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + - match: \b(?i:using)\b + scope: keyword.other.ddl.sql + - match: \b(?i:password) + scope: support.function.sql + push: function-call-arguments + - include: strings + - include: pop-on-top-level-reserved-word + + user-options: + - include: user-account-options + - include: user-password-options + - include: user-resource-options + - include: user-tls-options + - include: numbers + - include: strings + - include: pop-on-top-level-reserved-word + + user-account-options: + - match: \b(?i:account)\b + scope: keyword.other.ddl.sql + - match: \b(?i:unlock|lock)\b + scope: constant.language.sql + + user-password-options: + - match: \b(?i:(password)\s+(expire))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:default|never)\b + scope: constant.language.sql + - include: intervals + - include: time-units + + user-resource-options: + - match: \b(?i:with)\b + scope: keyword.other.ddl.sql + - match: |- + \b(?xi: max_queries_per_hour | max_updates_per_hour + | max_connections_per_hour | max_user_connections + | max_statement_time )\b + scope: constant.language.sql + + user-tls-options: + - match: \b(?i:require)\b + scope: keyword.other.ddl.sql + - match: \b(?i:and)\b + scope: keyword.operator.logical.sql + - match: \b(?i:ssl|x509|cipher|issuer|subject)\b + scope: constant.language.sql + - include: none-constants + + user-privileges: + - meta_append: true + - match: \b(?i:super)\b + scope: constant.language.sql + - include: user-grant-privileges + + user-grant-privileges: + - match: \b(?i:(?:grant|admin)\s+option)\b + scope: constant.language.sql + + on-privilidge-level: + - match: \b(?i:on)\b + scope: keyword.context.sql + set: privilidge-level + + privilidge-level: + # object type + - match: \b(?i:table|function|procedure|package)\b + scope: storage.type.sql + # wildcard privilidge level + - match: (\*)(?:(\.)(\*))? + scope: meta.other-name.sql + captures: + 1: constant.other.wildcard.asterisk.sql + 2: punctuation.accessor.dot.sql + 3: constant.other.wildcard.asterisk.sql + pop: 1 + # named privilidge level: database, table or method + - include: expect-other-name + +###[ TABLE NAMES OR SUBQUERIES ]############################################### + + table-subquery: + # https://mariadb.com/kb/en/join-syntax + - match: \( + scope: punctuation.section.group.begin.sql + set: table-subquery-begin + - match: \{ + scope: punctuation.section.braces.begin.mysql + set: + - table-braced-subquery-body + - maybe-on-table + + table-braced-subquery-body: + - meta_scope: meta.braces.mysql + - match: \} + scope: punctuation.section.braces.end.mysql + pop: 1 + - include: join-expressions + + maybe-on-table: + - match: \b(?i:on)\b + scope: keyword.other.dml.sql + set: table-name-or-subquery + - include: else-pop + + table-subquery-begin: + - meta_include_prototype: false + - meta_scope: meta.group.sql + - include: comments + # table subquery + - match: (?=(?i:select)\b) + set: + - maybe-table-alias + - inside-group + # table reference list + - match: (?=\S) + set: inside-table-reference-list + + inside-table-reference-list: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - include: expect-table-references + + expect-table-references: + - meta_include_prototype: false + - match: (?=\S) + push: + - join-condition + - table-name-or-subquery + + table-name-not-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-index-hint-list + - maybe-table-alias + - table-name-fail-if-function-call + - table-name + - single-identifier + + maybe-table-alias: + - meta_prepend: true + - match: (?=(?i:force|ignore|on|use|using)\b) + pop: 1 + - match: \b(?i:partition)\b + scope: keyword.other.dml.sql + push: maybe-partition-name-list + +###[ INDEX HINTS ]############################################################# + + maybe-index-hint-list: + # https://mariadb.com/kb/en/join-syntax + - include: index-hint-lists + - include: comma-separators + - include: else-pop + + index-hint-lists: + - match: \b(?i:(?:force|ignore|use)\s+(?:index|key))\b + scope: keyword.other.dml.sql + push: + - maybe-index-name-list + - maybe-index-hint-target + + maybe-index-hint-target: + - match: \b(?i:for\s+(?:join|(?:group|order)\s+by))\b + scope: keyword.other.dml.sql + pop: 1 + - include: else-pop + + maybe-index-name-list: + - match: \( + scope: punctuation.section.sequence.begin.sql + set: inside-index-name-list + - include: else-pop + + inside-index-name-list: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - include: expect-index-names + +###[ TYPES ]################################################################### + + intervals: + - match: \b(?i:interval)\b + scope: storage.type.interval.sql + + built-in-types: + - meta_prepend: true + # https://mariadb.com/kb/en/row + - match: \b(?i:row)\b + scope: storage.type.sql + push: + - after-type + - maybe-column-declaration-list + - match: \b(?i:set)(?=\s*\() + scope: storage.type.sql + push: + - after-type + - maybe-group + + built-in-type: + - meta_prepend: true + # https://mariadb.com/kb/en/row + - match: \b(?i:row)\b + scope: storage.type.sql + set: + - after-type + - maybe-column-declaration-list + - match: \b(?i:set)\b + scope: storage.type.sql + set: + - after-type + - maybe-group + + after-type: + - meta_prepend: true + - match: \b(?i:with(?:out)?\s+time\s+zone)\b + scope: storage.modifier.sql + pop: 1 + +###[ IDENTIFIERS ]############################################################# + + expect-user-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name-declaration, user-identifier] + + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - include: built-in-user-function-call + - match: (?=\S) + set: [user-name, user-identifier] + + user-identifier: + # https://mariadb.com/kb/en/grant/#account-names + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - identifier-host-accessor + - identifier-part + + identifier-host-accessor: + - meta_include_prototype: false + - match: \s*(@) + captures: + 1: punctuation.accessor.at.sql + set: identifier-host-part + - include: immediately-pop + + identifier-host-part: + - meta_include_prototype: false + - match: \% + scope: constant.other.wildcard.percent.sql + pop: 1 + - match: (')(%)(') + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (")(%)(") + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (`)(%)(`) + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-part + +###[ LITERALS ]################################################################ + + literals-and-variables: + - meta_append: true + - include: time-units + - include: variables + + comment-keywords: + - match: \b(?i:comment)\b + scope: variable.parameter.sql + + constants: + - meta_append: true + - include: bool-constants + - include: none-constants + - match: \b{{builtin_constants}}\b + scope: constant.language.sql + + bool-constants: + - include: booleans + - match: \b(?i:yes|no)\b + scope: constant.language.boolean.sql + + none-constants: + - match: \b(?i:none)\b + scope: constant.language.null.sql + + none-constant: + - match: \b(?i:none)\b + scope: constant.language.null.sql + pop: 1 + + time-units: + - match: \b{{time_units}}(?!\()\b + scope: keyword.other.unit.sql + + variables: + - match: (:){{simple_identifier}}\b + scope: variable.parameter.sql + captures: + 1: punctuation.definition.variable.sql + - match: (@@){{simple_identifier}}\b + scope: variable.language.sql + captures: + 1: punctuation.definition.variable.sql + - match: (@){{simple_identifier}}\b + scope: variable.other.sql + captures: + 1: punctuation.definition.variable.sql + + regexps: + - match: /(?=\S.*/) + scope: punctuation.definition.string.begin.sql + push: inside-regexp + + inside-regexp: + - meta_include_prototype: false + - meta_scope: meta.string.regexp.sql string.regexp.sql + - match: / + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolations + - match: \\/ + scope: constant.character.escape.slash.sql + + strings: + - meta_append: true + - include: double-quoted-strings + - include: interpolations + + double-quoted-strings: + - match: \" + scope: punctuation.definition.string.begin.sql + push: inside-double-quoted-string + + inside-double-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.double.sql + - match: \"\" + scope: constant.character.escape.sql + - match: \" + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolations + + interpolations: + - match: \%\{ + scope: punctuation.definition.string.begin.sql + push: inside-interpolation + + inside-interpolation: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.other.quoted.brackets.sql + - match: \} + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolations + + string-interpolations: + - meta_include_prototype: false + - match: (#\{)([^\}]*)(\}) + scope: meta.interpolation.sql + captures: + 1: punctuation.section.interpolation.begin.sql + 3: punctuation.section.interpolation.end.sql + push: clear-scope-imediately-pop + +###[ LIKE EXPRESSIONS ]######################################################## + + like-string-not-followed-by-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-fail + - inside-like-single-quoted-string-slash-escape + - include: else-pop + + like-escape-character-slash: + - match: (\')(\\\\)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + +###[ OPERATORS ]############################################################### + + operators: + - meta_append: true + - match: \|\| + scope: keyword.operator.concatenation.sql + - match: \! + scope: keyword.operator.logical.sql + - match: \b(?i:div|mod)\b + scope: keyword.operator.arithmetic.sql + +###[ PROTOTYPES ]############################################################## + + clear-scope-imediately-pop: + - clear_scopes: 1 + - include: immediately-pop diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax new file mode 100644 index 0000000000..04a64f1940 --- /dev/null +++ b/SQL/PostgreSQL.sublime-syntax @@ -0,0 +1,361 @@ +%YAML 1.2 +--- +name: PostgreSQL +scope: source.sql.psql +version: 2 + +extends: Packages/SQL/MySQL.sublime-syntax + +file_extensions: + - psql + +variables: + simple_types: |- + (?xi: smallint | integer | bigint | real | double\s+precision + | smallserial | serial | bigserial + | money + | bytea + | boolean + | times? | timestamp(?:s | tz)? | date | interval + | int4range | int8range | numrange | tsrange | tstzrange | daterange + | point | line | lseg | box | path | polygon | circle + | cidr | inet | macaddr | macaddr8 + | tsvector | tsquery + | uuid + | text | xml | jsonb? ) + + types_with_optional_number: |- + (?xi: (?: bit | character ) (?:\s+varying)? | char | decimal | numeric | varchar ) + +contexts: + + sql: + - meta_prepend: true + - include: declare-statements + + statements: + - meta_prepend: true + - match: (\$\$)\s+(LANGUAGE)\s+(\w+)(?:\s+(IMMUTABLE|STABLE)\b)? + captures: + 1: punctuation.section.block.end.psql + 2: keyword.other.psql + 3: constant.language.psql + 4: storage.modifier.psql + - match: \$\$ + scope: punctuation.section.block.begin.psql + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.psql + - match: \b(?i:for)\b + scope: keyword.control.loop.psql + push: + - declaration-variable-name + - single-identifier + - match: \b(?i:loop)\b + scope: keyword.control.loop.psql + # TODO: priortise variables over columns when not in a select statement etc. + + built-in-type: + - meta_prepend: true + - match: |- + (?xi) + \b{{types_with_optional_number}}\b + (\[)(\]) + scope: storage.type.sql + captures: + 1: punctuation.section.brackets.begin.psql + 2: punctuation.section.brackets.end.psql + set: maybe-group + +###[ DECLARE STATEMENTS ]###################################################### + + declare-statements: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.psql + push: inside-declaration + + inside-declaration: + - match: (?=\S) + set: + - expect-type + - declaration-variable-name + - single-identifier + + declaration-variable-name: + - meta_include_prototype: false + - meta_scope: variable.other.psql + - include: immediately-pop + +###[ DDL CREATE STATEMENTS ]################################################### + + create-target: + - meta_prepend: true + - include: create-extension + + create-extension: + # https://www.postgresql.org/docs/current/sql-createextension.html + - match: \b(?i:extension|domain)\b + scope: keyword.other.ddl.psql + set: + - create-extension-args + - expect-extension-name-declaration + - create-extension-condition + + create-extension-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-extension-args: + - meta_scope: meta.extension.sql + - match: \b(?i:with)\b + scope: keyword.other.psql + - match: \b(?i:schema)\b + scope: storage.modifier.psql + push: expect-schema-name + - include: extension-attributes + - include: expressions + + create-index-condition: + # https://www.postgresql.org/docs/current/sql-createindex.html + - meta_prepend: true + - match: \b(?i:concurrently)\b + scope: keyword.other.ddl.psql + + create-common-args: + - meta_prepend: true + - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b + scope: keyword.other.psql + push: maybe-on-table-name + - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b + scope: keyword.other.psql + +###[ DDL DROP STATEMENTS ]##################################################### + + drop-target: + - meta_prepend: true + - include: drop-extension + + drop-extension: + # https://www.postgresql.org/docs/current/sql-dropextension.html + - match: \b(?i:extension|domain)\b + scope: keyword.other.ddl.psql + set: + - drop-extension-args + - expect-extension-name + - drop-extension-condition + + drop-extension-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-extension-args: + - meta_scope: meta.extension.psql + - match: ',' + scope: punctuation.separator.sequence.psql + push: expect-extension-name + - include: extension-attributes + - include: else-pop + +###[ DDL ALTER STATEMENTS ]#################################################### + + alter-target: + - meta_prepend: true + # https://www.postgresql.org/docs/current/sql-alterextension.html + - match: \b(?i:extension|domain)\b + scope: keyword.other.ddl.psql + set: + - alter-extension-args + - expect-extension-name + + alter-extension-args: + - match: \b(?i:add|drop)\b + scope: keyword.other.ddl.sql + push: expect-member-name + - match: \b(?i:(set)\s+(schema))\b + captures: + 1: keyword.other.ddl.psql + 2: storage.modifier.psql + push: expect-schema-name + - match: \b(?i:(update)\s+(to))\b + captures: + 1: keyword.other.ddl.psql + 2: keyword.other.ddl.psql + - include: numbers + - include: else-pop + +###[ DDL STATEMENT PROTOTYPES ]################################################ + + on-table-names: + - match: \b(?i:(on)(?:\s+(only))?)\b + captures: + 1: keyword.other.sql + 2: keyword.other.psql + push: expect-table-name + +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_prepend: true + - match: \b(?i:array)\b + scope: keyword.declaration.psql + - match: \[ + scope: punctuation.section.brackets.begin.psql + - match: \] + scope: punctuation.section.brackets.end.psql + +###[ COLUMN EXPRESSIONS ]###################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:unique)\b + scope: keyword.other.psql + +###[ EXTENSION EXPRESSIONS ]################################################### + + extension-attributes: + - match: \b(?i:cascade|restrict|version)\b + scope: storage.modifier.psql + +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-characteristics: + # https://mariadb.com/kb/en/create-function + - meta_prepend: true + - match: \b(?i:as)\b + scope: keyword.other.ddl.sql + pop: 1 + +###[ IDENTIFIERS ]############################################################# + + expect-extension-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [extension-name, single-identifier] + + extension-name: + - meta_include_prototype: false + - meta_content_scope: meta.extension-name.psql + - include: immediately-pop + + expect-extension-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [extension-name-declaration, single-identifier] + + extension-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.namespace.psql + - include: immediately-pop + + expect-member-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [member-name, single-identifier] + + member-name: + - meta_include_prototype: false + - meta_content_scope: meta.member-name.psql + - include: immediately-pop + + expect-member-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [member-name-declaration, single-identifier] + + member-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.member.psql + - include: immediately-pop + + expect-schema-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [schema-name, single-identifier] + + schema-name: + - meta_include_prototype: false + - meta_content_scope: meta.schema-name.psql + - include: immediately-pop + +###[ OPERATORS ]############################################################### + + operators: + - meta_prepend: true + - match: '::' + scope: keyword.operator.cast.psql + push: expect-type + - match: ':=' + scope: keyword.operator.assignment.psql + - match: ':(?!:)' + scope: keyword.operator.range.psql + - include: regex-operators + - match: \.\. + scope: keyword.operator.psql + + regex-operators: + # https://www.postgresql.org/docs/7.4/functions-matching.html#FUNCTIONS-POSIX-REGEXP + - match: '!?~\*?' + scope: keyword.operator.comparison.psql + push: expect-regexp + + expect-regexp: + - match: \' + scope: meta.string.regexp.psql punctuation.definition.string.begin.psql + embed: scope:source.regexp + embed_scope: meta.string.regexp.psql + escape: \' + escape_captures: + 0: meta.string.regexp.psql punctuation.definition.string.end.psql + pop: 1 + - include: else-pop + + strings: + - meta_prepend: true + # https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE + - match: (?i:E)\' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-escape-string + - match: \'(?=[^']+'::bytea\b) + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-bytea-string + + inside-single-quoted-escape-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - match: \\[0-7]{1,3} + scope: constant.character.escape.sql + - match: \\x\h{1,2} + scope: constant.character.escape.sql + - match: \\u\h{4} + scope: constant.character.escape.sql + - match: \\U\h{8} + scope: constant.character.escape.sql + - include: string-escapes + + inside-single-quoted-bytea-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - match: \\[0-7]{1,3} + scope: constant.character.escape.sql + - match: \\x\h{8} + scope: constant.character.escape.sql + - include: string-escapes diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax new file mode 100644 index 0000000000..25818cce48 --- /dev/null +++ b/SQL/SQL (basic).sublime-syntax @@ -0,0 +1,1659 @@ +%YAML 1.2 +--- +name: SQL (Basic) +scope: source.sql.basic +version: 2 +hidden: true + +variables: + string_escape: (?:\\.) + simple_identifier: (?:\w+) + simple_identifier_break: (?!\w) + + toplevel_reserved: |- + (?xi: alter | create | cross | delete | drop | from | grant | group | inner | insert | join + | left | on | order | outer | revoke | right | select | set | truncate | union + | update | where ) + additional_toplevel_reserved: (?!) + + # TODO: not all are supported by all dialects! + ddl_target: |- + (?xi: {{ddl_target_other}} + | (?: {{ddl_target_function_modifier}} \s+ )? {{ddl_target_function}} + | (?: {{ddl_target_index_modifier}} \s+ )? index + | (?: {{ddl_target_table_modifier}} \s+ )? table ) + ddl_target_function: |- + (?xi: procedure | function ) + ddl_target_other: |- + (?xi: aggregate | column | constraint | conversion | database | domain | group + | language | member | operator\s+class | operator | role | rule | schema | sequence + | tablespace | trigger | type | user | view ) + + ddl_target_inside_alter_table: |- + (?xi: constraint ) + + ddl_target_function_modifier: |- + (?xi: aggregate ) + ddl_target_index_modifier: |- + (?xi: clustered | fulltext | spatial | unique ) + ddl_target_table_modifier: |- + (?xi: temp(?:orary)? ) + + function_parameter_modifier: |- + (?xi: inout | in | out ) + + simple_types: |- + (?xi: boolean | bool | year ) + + types_with_optional_number: |- + (?xi: bit | datetime | int | number | n?(?:var)?char | varbinary ) + + type_modifiers: |- + (?xi: signed | unsigned | zerofill ) + + builtin_scalar_functions: |- + (?xi: current_(?: date | time(?:stamp)? ) ) + + builtin_user_functions: |- + (?xi: (?: current | session | system )_user ) + +contexts: + prototype: + - include: comments + + main: + - include: sql + + sql: + - include: statements + - include: statement-terminators + - include: expressions-or-column-names + + statements: + - include: create-statements + - include: drop-statements + - include: alter-statements + - include: dml-statements + - include: grant-statements + - include: revoke-statements + - include: other-statements + +###[ COMMENTS ]################################################################ + + comments: + - include: double-dash-comments + - include: block-comments + + double-dash-comments: + - match: '--' + scope: punctuation.definition.comment.sql + push: inside-double-dash-comment + + block-comments: + - match: /\*(?:\*(?!/))+ + scope: punctuation.definition.comment.begin.sql + push: inside-comment-docblock + - match: /\* + scope: punctuation.definition.comment.begin.sql + push: inside-comment-block + + inside-double-dash-comment: + - meta_include_prototype: false + - meta_scope: comment.line.double-dash.sql + - match: \n + pop: 1 + + inside-comment-docblock: + - meta_include_prototype: false + - meta_scope: comment.block.documentation.sql + - match: \*+/ + scope: punctuation.definition.comment.end.sql + pop: 1 + - match: ^\s*(\*)(?!\**/) + captures: + 1: punctuation.definition.comment.sql + + inside-comment-block: + - meta_include_prototype: false + - meta_scope: comment.block.sql + - match: \*+/ + scope: punctuation.definition.comment.end.sql + pop: 1 + +###[ DDL CREATE STATEMENTS ]################################################### + + create-statements: + - match: \b(?i:create)\b + scope: keyword.other.ddl.sql + push: + - create-meta + - create-target + + create-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.create.sql + - include: immediately-pop + + create-target: + - include: create-function + - include: create-index + - include: create-table + - include: create-other + - include: else-pop + + create-function: + - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - expect-function-characteristics + - expect-function-parameters + - expect-function-creation-name + - create-function-condition + + create-function-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-index: + - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - create-index-args + - expect-index-creation-name + - create-index-condition + + create-index-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-index-args: + - meta_scope: meta.index.sql + - include: on-table-names + - include: create-common-args + + create-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - create-table-args + - maybe-column-declaration-list + - expect-table-creation-name + - create-table-condition + + create-table-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-table-args: + - meta_scope: meta.table.sql + - include: create-common-args + + create-other: + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - create-other-args + - expect-other-creation-name + - create-other-condition + + create-other-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-other-args: + - match: \b(?i:(as)\s+(table))\b + captures: + 1: keyword.context.block.sql + 2: support.type.sql + set: maybe-column-declaration-list + - match: \b(?i:as)\b + scope: keyword.context.block.sql + pop: 1 + - include: grant + - include: on-table-names + - include: create-common-args + + create-common-args: + - include: expressions + - include: pop-on-top-level-reserved-word + +###[ DDL DROP STATEMENTS ]##################################################### + + drop-statements: + - match: \b(?i:drop)\b + scope: keyword.other.ddl.sql + push: + - drop-meta + - drop-target + + drop-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.drop.sql + - include: immediately-pop + + drop-target: + - include: drop-function + - include: drop-index + - include: drop-table + - include: drop-other + - include: else-pop + + drop-function: + - match: \b{{ddl_target_function}}\b + scope: keyword.other.ddl.sql + set: + - drop-function-args + - expect-function-name + - drop-function-condition + + drop-function-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-function-args: + - meta_include_prototype: false + - meta_scope: meta.function.sql + - include: immediately-pop + + drop-index: + - match: \b(?i:index)\b + scope: keyword.other.ddl.sql + set: + - drop-index-args + - expect-index-name + - drop-index-condition + + drop-index-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-index-args: + - meta_scope: meta.index.sql + - include: maybe-on-table-name + + drop-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - drop-table-args + - expect-table-name + - drop-table-condition + + drop-table-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-table-args: + - meta_include_prototype: false + - meta_scope: meta.table.sql + - include: immediately-pop + + drop-other: + - match: \b(?i:user)\b + scope: storage.type.sql + set: + - expect-user-name + - maybe-condition + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - drop-other-args + - expect-other-name + - drop-other-condition + + drop-other-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-other-args: + - include: maybe-on-table-name + +###[ DDL ALTER STATEMENTS ]#################################################### + + alter-statements: + - match: \b(?i:alter)\b + scope: keyword.other.ddl.sql + push: + - alter-meta + - alter-target + + alter-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.alter.sql + - include: immediately-pop + + alter-target: + - include: alter-function + - include: alter-index + - include: alter-table + - include: alter-other + - include: else-pop + +###[ DDL ALTER FUNCTION STATEMENTS ]########################################### + + alter-function: + - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - expect-function-characteristics + - expect-function-parameters + - expect-function-name + - alter-function-condition + + alter-function-condition: + - meta_include_prototype: false + - include: maybe-condition + +###[ DDL ALTER INDEX STATEMENTS ]############################################## + + alter-index: + - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - alter-index-args + - expect-index-name + - alter-index-condition + + alter-index-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-index-args: + - include: alter-common + - include: pop-on-top-level-reserved-word + - include: expressions-or-column-names + +###[ DDL ALTER TABLE STATEMENTS ]############################################## + + alter-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - alter-table-args + - expect-table-name + - alter-table-condition + + alter-table-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-table-args: + - include: alter-columns + - include: alter-common + - include: pop-on-top-level-reserved-word + - include: expressions-or-column-names + + alter-other: + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - alter-other-args + - expect-other-name + - alter-other-condition + + alter-other-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-other-args: + - include: alter-common + - include: else-pop + + alter-columns: + - match: \b(?i:(?:(add|alter)\b(?:\s+(column)\b|(?!\s+(?:table|{{ddl_target_inside_alter_table}})\b)))) + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - expect-type + - expect-column-name-declaration + - match: \b(?i:(drop)(?:\s+(column)\b|(?!\s+{{ddl_target}}\b))) + scope: keyword.other.ddl.sql + push: expect-column-name + + alter-common: + - match: \b(?i:(add)\s+(constraint))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - maybe-column-modifier + - expect-constraint-name + - match: \b(?i:(add)\s+(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + - match: \b(?i:(add)\s+(primary|foreign)\s+(key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + +###[ DDL STATEMENT PROTOTYPES ]################################################ + + maybe-on-table-name: + - include: on-table-names + - include: else-pop + + on-table-names: + - match: \b(?i:on)\b + scope: keyword.other.sql + push: expect-table-name + +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - match: \b(?i:select)\b + scope: keyword.other.dml.sql + - match: \b(?i:union(?:\s+all)?)\b + scope: keyword.other.dml.sql + - match: \b(?i:(?:delete(?:\s+from)?))\b + scope: keyword.other.dml.sql + push: dml-delete + - match: \b(?i:update)\b + scope: keyword.other.dml.sql + push: dml-update + - match: \b(?i:(?:insert\s+into|truncate))\b + scope: keyword.other.dml.sql + push: expect-table-name + - include: set-statements + # expressions + - match: \b(?i:(?:default\s+)?values)\b + scope: keyword.other.dml.II.sql + - include: distinct + - include: join-expressions + - match: \b(?i:group\s+by|order\s+by|having|where)\b + scope: keyword.other.dml.sql + - match: \b(?i:from)\b + scope: keyword.other.dml.sql + push: table-name-or-subquery + - match: \b(?i:asc|desc)\b + scope: keyword.other.order.sql + + dml-delete: + - include: expect-table-name + + dml-update: + - match: (?={{simple_identifier}}\s*=) + pop: 1 + - include: expect-table-name + + distinct: + - match: \b(?i:distinct)\b + scope: keyword.other.dml.sql + + join-expressions: + - match: \b(?i:(?:(?:cross|inner|(?:full|left|right)(?:\s+outer)?)\s+)?join)\b + scope: keyword.other.dml.sql + push: + - join-condition + - table-name-or-subquery + + join-condition: + - match: \b(?i:on)\b + scope: keyword.control.conditional.sql + set: conditional-expression + - include: else-pop + + conditional-expression: + - match: (?=[,;)}]|\b(?:{{toplevel_reserved}}|{{additional_toplevel_reserved}})\b) + pop: 1 + - include: expressions + - include: expect-column-names + +###[ DML SET STATEMENTS ]###################################################### + + set-statements: + - match: \b(?i:set)\b(?!\s*\() + scope: keyword.other.dml.sql + push: + - set-meta + - set-target + + set-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.set.sql + - include: immediately-pop + + set-target: + - include: else-pop + +###[ GRANT STATEMENTS ]######################################################## + + grant-statements: + - match: \b(?i:grant(?:\s+with\s+grant\s+option)?)\b + scope: keyword.other.authorization.sql + push: + - grant-meta + - grant + + grant-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.grant.sql + - include: immediately-pop + +###[ REVOKE STATEMENTS ]####################################################### + + revoke-statements: + - match: \b(?i:revoke)\b + scope: keyword.other.ddl.sql + push: + - revoke-meta + - grant + + revoke-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.revoke.sql + - include: immediately-pop + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: [] + +###[ EXPRESSIONS ]############################################################# + + expressions-or-column-names: + - include: wildcard-identifiers + - include: expressions + - include: expect-column-names + + expressions: + - include: groups + - include: comma-separators + - include: operators + - include: column-alias-expressions + - include: case-expressions + - include: collate-expressions + - include: constraint-expressions + - include: literals-and-variables + - include: function-calls + - include: illegal-stray-brackets + - include: illegal-stray-parens + - match: (?=;) + pop: 1 + + column-alias-expressions: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + push: expect-column-alias-name + + table-alias-expression: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + set: expect-table-alias-name + + case-expressions: + - match: \b(?i:case)\b + scope: keyword.control.conditional.case.sql + push: inside-case-expression + + inside-case-expression: + - meta_scope: meta.statement.conditional.case.sql + - match: \b(?i:end)\b + scope: keyword.control.conditional.end.sql + pop: 1 + - match: \b(?i:(case)\s+(when))\b + captures: + 1: keyword.control.conditional.case.sql + 2: keyword.control.conditional.when.sql + - match: \b(?i:when)\b + scope: keyword.control.conditional.when.sql + - match: \b(?i:then)\b + scope: keyword.control.conditional.then.sql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.sql + - include: expressions-or-column-names + + collate-expressions: + - match: \b(?i:collate)\b + scope: keyword.other.sql + push: inside-collate-expression + + inside-collate-expression: + - match: '{{simple_identifier}}' + scope: support.constant.sql + pop: 1 + - include: else-pop + + constraint-expressions: + - match: \b(?i:constraint)\b + scope: storage.modifier.sql + push: expect-constraint-name + + maybe-check: + - match: \b(?i:check)\b + scope: keyword.other.sql + set: maybe-group + - include: else-pop + + maybe-column: + - match: \b(?i:column)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + + maybe-to: + - match: \b(?i:to)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + +###[ FUNCTION EXPRESSIONS ]#################################################### + + function-calls: + - include: built-in-aggregate-function-calls + - include: built-in-scalar-function-calls + - include: built-in-user-function-calls + - include: user-defined-function-calls + + built-in-aggregate-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + scope: support.function.aggregate.sql + push: function-call-arguments + + built-in-scalar-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b{{builtin_scalar_functions}}\b + scope: support.function.scalar.sql + push: function-call-arguments + + built-in-user-function-calls: + - match: \b{{builtin_user_functions}}\b + scope: support.function.user.sql + push: function-call-arguments + + built-in-user-function-call: + - match: \b{{builtin_user_functions}}\b + scope: support.function.user.sql + set: function-call-arguments + + user-defined-function-calls: + - match: \b{{simple_identifier}}(?=\s*\() + scope: support.function.sql + push: function-call-arguments + + function-call-arguments: + - meta_include_prototype: false + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.arguments.begin.sql + set: inside-function-call-arguments + - include: else-pop + + inside-function-call-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.arguments.sql + - include: distinct + - include: expressions-or-column-names + +###[ GROUPS EXPRESSIONS ]###################################################### + + maybe-group: + - include: group + - include: else-pop + + group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-group + + groups: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-group + + inside-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: sql + +###[ COLUMN EXPRESSIONS ]###################################################### + + expect-column-declaration: + - include: column-declaration-list + - match: (?=\S) + set: + - maybe-column-modifier + - after-type + - expect-type + - column-name-declaration + - single-identifier + + maybe-column-declaration-list: + - include: column-declaration-list + - include: else-pop + + column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-declaration-list + + inside-column-declaration-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: column-modifiers + - include: expressions + - include: expect-column-declarations + + expect-column-declarations: + - match: (?=\S) + push: + - maybe-column-modifier + - after-type + - expect-type + - column-name-declaration + - single-identifier + + maybe-column-modifier: + - include: column-modifiers + - include: else-pop + + column-modifiers: + - match: \b(?i:check)\b + scope: keyword.other.sql + - match: |- + \b(?xi: + (?: (?: fulltext | primary | unique ) \s+ )? key + | on \s+ (?: delete | update ) (?: \s+ cascade )? + | default + )\b + scope: storage.modifier.sql + - match: |- + \b(?xi: + foreign\s+key + )\b + scope: storage.modifier.sql + push: column-name-list + - match: \b(?i:unique)\b + scope: storage.modifier.sql + push: maybe-column-name-list + - match: \b(?i:references)\b + scope: storage.modifier.sql + push: + - maybe-column-name-list + - expect-table-name + + maybe-column-name-list: + - include: column-name-list + - include: else-pop + + column-name-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-name-list + + column-name-lists: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-column-name-list + + inside-column-name-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: expressions-or-column-names + +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-parameters: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-function-parameters + - include: else-pop + + inside-function-parameters: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.sql meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - match: (?=\S) + push: + - expect-type + - expect-parameter-name + - maybe-parameter-modifier + + expect-parameter-name: + - match: '{{simple_identifier}}' + scope: variable.parameter.sql + pop: 1 + - include: else-pop + + maybe-parameter-modifier: + - match: \b{{function_parameter_modifier}}\b + scope: storage.modifier.sql + pop: 1 + - include: else-pop + + expect-function-characteristics: + - meta_scope: meta.function.sql + - match: \b(?i:as|return)\b + scope: keyword.context.block.sql + pop: 1 + - match: \b(?i:language)\b + scope: storage.modifier.sql + push: expect-function-language-name + - match: \b(?i:returns)\b + scope: keyword.other.ddl.sql + push: expect-type + - include: create-common-args + + expect-function-language-name: + - match: '{{simple_identifier}}' + scope: constant.other.language.sql + pop: 1 + - include: else-pop + +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + grant: + - match: \b(?i:to)\b + scope: keyword.context.sql + push: expect-user-name + - include: comma-separators + - include: user-privileges + - include: pop-on-top-level-reserved-word + + user-privileges: + - include: column-name-lists + - match: \b(?i:all(?:\s+privileges)?)\b + scope: constant.language.sql + - match: \b(?i:(?:alter|create|drop|grant|revoke)\s+{{ddl_target}})\b + scope: constant.language.sql + - match: \b(?i:select|insert|update|delete|truncate|execute)\b + scope: constant.language.sql + +###[ TABLE NAMES OR SUBQUERIES ]############################################### + + table-name-or-subquery: + - meta_include_prototype: false + - include: table-subquery + - include: table-name-or-function-call + + table-subquery: + - match: (?=\() + set: + - maybe-table-alias + - group + + table-name-or-function-call: + - match: (?=\S) + pop: 1 # pop `table-name-or-subquery` before evaluating branches + branch_point: table-name-or-function-call + branch: + - table-name-not-function-call + - table-valued-function-call + + table-name-not-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-table-alias + - table-name-fail-if-function-call + - table-name + - single-identifier + + table-name-fail-if-function-call: + - meta_include_prototype: false + - match: (?=\() + fail: table-name-or-function-call + - match: (?=\S) + pop: 1 + + table-valued-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-table-alias + - function-call-arguments + - table-valued-function-name + - single-identifier + + table-valued-function-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-valued-function-name.sql + - include: immediately-pop + + maybe-table-alias: + - include: pop-on-top-level-reserved-word + - include: table-timespecs + - include: table-alias-expression + - include: expect-table-alias-name + + table-timespecs: + - match: \b(?i:for\s+system_time)\b + scope: keyword.other.dml.sql + push: table-timespec-args + + table-timespec-args: + - match: \b(?i:as\s+of|between|and|from|to)\b + scope: keyword.operator.logical.sql + push: + - table-timespec-expression + - table-timespec-type + - match: \b(?i:all)\b + scope: constant.other.sql + pop: 1 + - include: else-pop + + table-timespec-type: + - match: \b(?i:timestamp|transaction)\b + scope: storage.type.sql + set: else-pop + - include: else-pop + + table-timespec-expression: + - include: expressions + - include: immediately-pop + +###[ TYPES ]################################################################### + + expect-type: + - meta_include_prototype: false + - include: comments + - include: built-in-type + - include: expect-user-type + + built-in-types: + - match: \b(?i:enum)\b + scope: storage.type.sql + push: + - after-type + - maybe-group + - match: |- + (?x) + \b(?: {{simple_types}} | {{types_with_optional_number}} ) + (?: ((\()(\d+)(?:\s*(,)\s*(\d+))?(\)) | \b(?!\s*\() ) ) + scope: storage.type.sql + captures: + 1: meta.parens.sql + 2: punctuation.definition.parens.begin.sql + 3: meta.number.integer.decimal.sql constant.numeric.value.sql + 4: punctuation.separator.sequence.sql + 5: meta.number.integer.decimal.sql constant.numeric.value.sql + 6: punctuation.definition.parens.end.sql + push: after-type + - match: \b{{type_modifiers}}\b + scope: storage.modifier.sql + + built-in-type: + - match: \b(?i:enum)\b + scope: storage.type.sql + set: + - after-type + - maybe-group + - match: |- + (?x) + \b(?: {{simple_types}} | {{types_with_optional_number}} ) + (?: ((\()(\d+)(?:\s*(,)\s*(\d+))?(\)) | \b(?!\s*\() ) ) + scope: storage.type.sql + captures: + 1: meta.parens.sql + 2: punctuation.definition.parens.begin.sql + 3: meta.number.integer.decimal.sql constant.numeric.value.sql + 4: punctuation.separator.sequence.sql + 5: meta.number.integer.decimal.sql constant.numeric.value.sql + 6: punctuation.definition.parens.end.sql + set: after-type + + expect-user-type: + - match: (?=\S) + set: [maybe-group, after-type, inside-user-type] + + inside-user-type: + # note: may contain foreign variable interpolation + - meta_scope: support.type.sql + - match: '{{simple_identifier_break}}' + pop: 1 + + after-type: + - match: \b{{type_modifiers}}\b + scope: storage.modifier.sql + pop: 1 + - include: assignment-operators + - include: else-pop + +###[ IDENTIFIERS ]############################################################# + + expect-table-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [table-alias-name, single-identifier] + + expect-column-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-alias-name, single-identifier] + + table-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.alias.table.sql + - include: immediately-pop + + column-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.alias.column.sql + - include: immediately-pop + + expect-column-names: + - match: (?=\S) + push: [maybe-operator, column-name, single-identifier] + + expect-column-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-name, single-identifier] + + column-name: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql + - include: immediately-pop + + expect-column-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-name-declaration, single-identifier] + + column-name-declaration: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql + - include: immediately-pop + + expect-constraint-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - match: (?=(?i:check|foreign|primary|unique|index|key|using|with)\b) + pop: 1 + - include: comments + - match: (?=\S) + set: [constraint-name, single-identifier] + + constraint-name: + - meta_include_prototype: false + - meta_content_scope: meta.constraint-name.sql + - include: immediately-pop + + expect-database-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [database-creation-name, single-identifier] + + database-creation-name: + - meta_include_prototype: false + - meta_content_scope: entity.name.struct.database.sql + - include: immediately-pop + + expect-database-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [database-name, single-identifier] + + database-name: + - meta_include_prototype: false + - meta_content_scope: meta.database-name.sql + - include: immediately-pop + + expect-event-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [event-creation-name, single-identifier] + + event-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.event.sql + - include: immediately-pop + + expect-event-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [event-name, single-identifier] + + event-name: + - meta_include_prototype: false + - meta_scope: meta.event-name.sql + - include: immediately-pop + + expect-index-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [index-creation-name, single-identifier] + + index-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.index.sql + - include: immediately-pop + + expect-index-names: + - match: (?=\S) + push: [index-name, single-identifier] + + expect-index-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [index-name, single-identifier] + + index-name: + - meta_include_prototype: false + - meta_scope: meta.index-name.sql + - include: immediately-pop + + expect-function-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [procedure-creation-name, single-identifier] + + expect-partition-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [partition-creation-name, single-identifier] + + partition-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.partition.sql + - include: immediately-pop + + expect-partition-names: + - match: (?=\S) + push: [partition-name, single-identifier] + + expect-partition-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [partition-name, single-identifier] + + partition-name: + - meta_include_prototype: false + - meta_scope: meta.partition-name.sql + - include: immediately-pop + + procedure-creation-name: + - meta_include_prototype: false + - meta_content_scope: entity.name.function.sql + - include: immediately-pop + + expect-function-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [procedure-name, single-identifier] + + procedure-name: + - meta_include_prototype: false + - meta_content_scope: meta.procedure-name.sql + - include: immediately-pop + + expect-table-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [table-creation-name, single-identifier] + + table-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.table.sql + - include: immediately-pop + + expect-table-names: + - match: (?=\S) + push: [table-name, single-identifier] + + expect-table-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [table-name, single-identifier] + + table-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-name.sql + - include: immediately-pop + + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - include: built-in-user-function-call + - match: (?=\S) + set: [user-name, single-identifier] + + user-name: + - meta_include_prototype: false + - meta_content_scope: meta.username.sql + - include: immediately-pop + + expect-user-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name-declaration, single-identifier] + + user-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.user.sql + - include: immediately-pop + + expect-type-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [type-creation-name, single-identifier] + + type-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.type.cql + - include: immediately-pop + + expect-other-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [other-creation-name, single-identifier] + + other-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.other.sql + - include: immediately-pop + + expect-other-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [other-name, single-identifier] + + other-name: + - meta_include_prototype: false + - meta_scope: meta.other-name.sql + - include: immediately-pop + + single-identifier: + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - maybe-identifier-accessor + - identifier-part + + maybe-identifier-accessor: + - meta_include_prototype: false + - match: \s*(\.)\s*(\*) + captures: + 1: punctuation.accessor.dot.sql + 2: constant.other.wildcard.asterisk.sql + pop: 1 + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier + - include: immediately-pop + + identifier-part: + - meta_include_prototype: false + - include: backtick-quoted-identifier-part + - include: double-quoted-identifier-part + - include: single-quoted-identifier-part + - include: simple-identifier-part + + backtick-quoted-identifier-part: + - match: \` + scope: punctuation.definition.identifier.begin.sql + set: inside-backtick-quoted-identifier-part + + inside-backtick-quoted-identifier-part: + # note: may contain foreign variable interpolation + - match: \` + scope: punctuation.definition.identifier.end.sql + pop: 1 + + double-quoted-identifier-part: + - match: \" + scope: punctuation.definition.identifier.begin.sql + set: inside-double-quoted-identifier-part + + inside-double-quoted-identifier-part: + # note: may contain foreign variable interpolation + - match: \" + scope: punctuation.definition.identifier.end.sql + pop: 1 + + single-quoted-identifier-part: + - match: \' + scope: punctuation.definition.identifier.begin.sql + set: inside-single-quoted-identifier-part + + inside-single-quoted-identifier-part: + # note: may contain foreign variable interpolation + - match: \' + scope: punctuation.definition.identifier.end.sql + pop: 1 + + simple-identifier-part: + - match: (?=\S) + set: inside-simple-identifier-part + + inside-simple-identifier-part: + # note: may contain foreign variable interpolation + - match: '{{simple_identifier_break}}' + pop: 1 + + wildcard-identifiers: + - match: \* + scope: constant.other.wildcard.asterisk.sql + +###[ LITERALS ]################################################################ + + literals-and-variables: + - include: built-in-types + - include: constants + - include: numbers + - include: strings + + constants: + - match: \b(?i:null)\b + scope: constant.language.null.sql + + booleans: + - match: \b(?i:true)\b + scope: constant.language.boolean.true.sql + - match: \b(?i:false)\b + scope: constant.language.boolean.false.sql + + numbers: + - match: \b\d+(\.)\d+\b + scope: meta.number.float.decimal.sql constant.numeric.value.sql + captures: + 1: punctuation.separator.decimal.sql + - match: \b\d+\b + scope: meta.number.integer.decimal.sql constant.numeric.value.sql + + strings: + - match: \' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-string + + inside-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-escapes + + string-escapes: + - match: '{{string_escape}}' + scope: constant.character.escape.sql + +###[ LIKE EXPRESSIONS ]######################################################## + + like-expressions: + - match: \b(?i:like)\b + scope: keyword.operator.logical.sql + branch_point: like-expressions + branch: + - like-string-not-followed-by-escape + - like-string-followed-by-escape-slash + - like-string-followed-by-escape-caret + - like-string-followed-by-escape-hash + - like-string-followed-by-unknown-escape + + like-string-not-followed-by-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-fail + - inside-like-single-quoted-string + - include: else-pop + + like-string-followed-by-escape-slash: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-slash + - like-escape + - inside-like-single-quoted-string-slash-escape + - include: else-pop + + like-string-followed-by-escape-caret: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-caret + - like-escape + - inside-like-single-quoted-string-caret-escape + - include: else-pop + + like-string-followed-by-escape-hash: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-hash + - like-escape + - inside-like-single-quoted-string-hash-escape + - include: else-pop + + like-string-followed-by-unknown-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-any + - like-escape + - inside-like-single-quoted-string + - include: else-pop + + inside-like-single-quoted-string-slash-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \\. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string-caret-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \^. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string-hash-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: '#.' + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - match: '%' + scope: constant.other.wildcard.percent.sql + - match: '_' + scope: constant.other.wildcard.underscore.sql + + like-else-fail: + - match: (?=\S) + fail: like-expressions + + like-escape-fail: + - match: \b(?i:escape)\b + fail: like-expressions + - include: else-pop + + like-escape: + - match: \b(?i:escape)\b + scope: keyword.operator.word.sql + pop: 1 + - include: else-pop + + like-escape-character-any: + - match: (\')([^'])(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: else-pop + + like-escape-character-caret: + - match: (\')(\^)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + + like-escape-character-slash: + - match: (\')(\\)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + + like-escape-character-hash: + - match: (\')(#)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + +###[ OPERATORS ]############################################################### + + maybe-condition: + - meta_include_prototype: false + - include: conditions + - include: else-pop + + conditions: + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.sql + - include: logical-operators + + maybe-operator: + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + pop: 1 + - match: '[-+/*]' + scope: keyword.operator.arithmetic.sql + pop: 1 + - match: \b(?i:and|or|having|exists|between|in|not|is)\b + scope: keyword.operator.logical.sql + pop: 1 + - include: else-pop + + operators: + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + - match: '[-+/*]' + scope: keyword.operator.arithmetic.sql + - include: logical-operators + + assignment-operators: + - match: '=' + scope: keyword.operator.assignment.sql + + logical-operators: + - match: \b(?i:and|or|having|exists|between|in|not|is)\b + scope: keyword.operator.logical.sql + + comma-separators: + - match: ',' + scope: punctuation.separator.sequence.sql + + statement-terminators: + - match: ';' + scope: punctuation.terminator.statement.sql + +###[ ILLEGALS ]################################################################ + + illegal-stray-brackets: + - match: \] + scope: invalid.illegal.stray.sql + + illegal-stray-parens: + - match: \) + scope: invalid.illegal.stray.sql + +###[ PROTOTYPES ]############################################################## + + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + pop-on-top-level-reserved-word: + - match: (?=[;)}]|\b(?:{{toplevel_reserved}}|{{additional_toplevel_reserved}})\b) + pop: 1 diff --git a/SQL/SQL.sublime-syntax b/SQL/SQL.sublime-syntax index 262738ed9f..8a9c5e51f9 100644 --- a/SQL/SQL.sublime-syntax +++ b/SQL/SQL.sublime-syntax @@ -2,6 +2,9 @@ --- name: SQL scope: source.sql +version: 2 + +extends: Packages/SQL/MySQL.sublime-syntax file_extensions: - sql @@ -12,382 +15,3 @@ first_line_match: |- (?xi: ^ \s* -- .*? -\*- .*? \bsql\b .*? -\*- # editorconfig ) - -variables: - end_identifier: (?=[ \t]*(?:[^\w'"`. \t]|$)) - -contexts: - prototype: - - include: comments - main: - - match: |- - (?xi) - \b(create(?:\s+or\s+replace)?)\s+ - (aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) - \b\s* - scope: meta.create.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - push: create-condition - - match: (?i:\s*\b(drop)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|procedure|rule|schema|sequence|table|tablespace|trigger|type|user|view)) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - push: drop-condition - - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - 3: entity.name.function.sql - 4: keyword.other.cascade.sql - - match: (?i:\s*\b(alter)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|procedure|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+) - scope: meta.alter.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - - match: (?i:\s*\b(add)\s+(column|constraint|fulltext\s+(index|key)|index|spatial\s+(index|key))) - scope: meta.add.sql - captures: - 1: keyword.other.add.sql - 2: keyword.other.sql - - match: |- - (?xi) - - # normal stuff, capture 1 - \b(bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer|line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext)\b - - # numeric suffix, capture 2 + 3i - |\b(bit\svarying|character\s+(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) - - # optional numeric suffix, capture 4 + 5i - |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? - - # special case, capture 6 + 7i + 8i - |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? - - # special case, captures 9, 10i, 11 - |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\s+time\s+zone\b)? - - # special case, captures 12, 13, 14i, 15 - |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\s+time\s+zone\b)? - - - captures: - 1: storage.type.sql - 2: storage.type.sql - 3: constant.numeric.sql - 4: storage.type.sql - 5: constant.numeric.sql - 6: storage.type.sql - 7: constant.numeric.sql - 8: constant.numeric.sql - 9: storage.type.sql - 10: constant.numeric.sql - 11: storage.type.sql - 12: storage.type.sql - 13: storage.type.sql - 14: constant.numeric.sql - 15: storage.type.sql - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) - scope: storage.modifier.sql - - match: \b\d+\b - scope: constant.numeric.sql - - match: (?i:\bfalse\b) - scope: constant.language.boolean.false.sql - - match: (?i:\btrue\b) - scope: constant.language.boolean.true.sql - - match: (?i:\b(null)\b) - scope: constant.language.null.sql - - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|case|when|then|else|end|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) - scope: keyword.other.DML.sql - - include: logical-operators - - match: (?i:\blike\b) - scope: keyword.operator.logical.sql - branch_point: like-strings-branch - branch: - - like-string-not-followed-by-escape - - like-string-followed-by-escape-slash - - like-string-followed-by-escape-caret - - like-string-followed-by-unknown-escape - - match: (?i:\bvalues\b) - scope: keyword.other.DML.II.sql - - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) - scope: keyword.other.LUW.sql - - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) - scope: keyword.other.authorization.sql - - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) - scope: keyword.other.object-comments.sql - - match: (?i)\bas\b - scope: keyword.operator.assignment.alias.sql - - match: (?i)\b(asc|desc)\b - scope: keyword.other.order.sql - - match: \* - scope: constant.other.wildcard.asterisk.sql - - match: "<=>|[!<>]?=|<>|<|>" - scope: keyword.operator.comparison.sql - - match: '-|\+|/' - scope: keyword.operator.arithmetic.sql - - match: \|\| - scope: keyword.operator.concatenation.sql - - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.scalar.sql - - match: (?i)\b(AVG|COUNT|MIN|MAX|SUM)(?=\s*\() - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.aggregate.sql - - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b - scope: support.function.string.sql - - match: \b(\w+?)\.(\w+)\b - captures: - 1: constant.other.database-name.sql - 2: constant.other.table-name.sql - - include: strings - - include: regexps - - match: (\()(\)) - comment: Allow for special ↩ behavior - scope: meta.block.sql - captures: - 1: punctuation.section.scope.begin.sql - 2: punctuation.section.scope.end.sql - - match: (?i)\bon\b - scope: keyword.operator.word.sql - - match: ',' - scope: punctuation.separator.sequence.sql - - match: ';' - scope: punctuation.terminator.statement.sql - comments: - - meta_include_prototype: false - - match: '--' - scope: punctuation.definition.comment.sql - push: inside-double-dash-comment - - match: '#' - scope: punctuation.definition.comment.sql - push: inside-number-sign-comment - - match: /\* - scope: punctuation.definition.comment.begin.sql - push: inside-comment-block - inside-double-dash-comment: - - meta_include_prototype: false - - meta_scope: comment.line.double-dash.sql - - match: \n - pop: true - inside-number-sign-comment: - - meta_include_prototype: false - - meta_scope: comment.line.number-sign.sql - - match: \n - pop: true - inside-comment-block: - - meta_include_prototype: false - - meta_scope: comment.block.sql - - match: \*/ - scope: punctuation.definition.comment.end.sql - pop: true - - match: ^\s*(\*)(?!/) - captures: - 1: punctuation.definition.comment.sql - regexps: - - match: /(?=\S.*/) - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.regexp.sql - - match: / - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - - match: \\/ - scope: constant.character.escape.slash.sql - - match: '%r\{' - comment: We should probably handle nested bracket pairs!?! -- Allan - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.regexp.modr.sql - - match: '\}' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - string-escape: - - meta_include_prototype: false - - match: \\. - scope: constant.character.escape.sql - string-interpolation: - - meta_include_prototype: false - - match: '(#\{)([^\}]*)(\})' - scope: string.interpolated.sql - captures: - 1: punctuation.definition.string.begin.sql - 3: punctuation.definition.string.end.sql - strings: - - match: "'" - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.single.sql - - match: "''" - scope: constant.character.escape.sql - - match: "'" - scope: punctuation.definition.string.end.sql - pop: true - - include: string-escape - - match: "`" - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.other.backtick.sql - - match: "`" - scope: punctuation.definition.string.end.sql - pop: true - - include: string-escape - - match: '"' - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.double.sql - - match: '""' - scope: constant.character.escape.sql - - match: '"' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - - match: '%\{' - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.other.quoted.brackets.sql - - match: '\}' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - identifier-create: - - meta_content_scope: meta.toc-list.full-identifier.sql - - match: '(?:(\w+)|''([^'']+)''|"([^"]+)"|`([^`]+)`){{end_identifier}}' - scope: meta.toc-list.full-identifier.sql - captures: - 1: entity.name.function.sql - 2: entity.name.function.sql - 3: entity.name.function.sql - 4: entity.name.function.sql - pop: true - # Schema identifiers - - match: (?:\w+|'[^']+'|"[^"]+"|`[^`]+`)\s*(\.) - captures: - 1: punctuation.accessor.dot.sql - # Handle situations where the schema and . - - match: '{{end_identifier}}' - pop: true - create-condition: - - include: dml-condition - - match: (?=\S) - set: identifier-create - drop-condition: - - include: dml-condition - - match: (?=\S) - pop: true - dml-condition: - - match: (?i:\b(if)\b) - scope: keyword.control.flow.sql - - include: logical-operators - logical-operators: - - match: (?i:\b(and|or|having|exists|between|in|not|is)\b) - scope: keyword.operator.logical.sql - like-string-not-followed-by-escape: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-fail, inside-like-single-quoted-string] - - match: (?=\S) - pop: true - like-string-followed-by-escape-slash: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-character-slash, like-escape-pop, inside-like-single-quoted-string-slash-escape] - - match: (?=\S) - pop: true - like-string-followed-by-escape-caret: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-character-caret, like-escape-pop, inside-like-single-quoted-string-caret-escape] - - match: (?=\S) - pop: true - like-string-followed-by-unknown-escape: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-character-any, like-escape-pop, inside-like-single-quoted-string] - - match: (?=\S) - pop: true - inside-like-single-quoted-string-slash-escape: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \\. - scope: constant.character.escape.sql - - include: inside-like-single-quoted-string - inside-like-single-quoted-string-caret-escape: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \^. - scope: constant.character.escape.sql - - include: inside-like-single-quoted-string - inside-like-single-quoted-string: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \' - scope: punctuation.definition.string.end.sql - pop: true - - match: |- - (?x) - (\[)(\^)? - (?:.|[^]'-]+?) - (?:(-)[^]'-]*)? - (\]) - scope: meta.set.like.sql - captures: - 1: keyword.control.set.begin.sql - 2: keyword.control.set.negation.sql - 3: constant.other.range.sql - 4: keyword.control.set.end.sql - - match: '[%_]' - scope: keyword.operator.wildcard.sql - like-escape-fail: - - match: (?i:\bescape\b) - fail: like-strings-branch - - match: (?=\S) - pop: true - like-escape-pop: - - match: (?i:\bescape\b) - scope: keyword.operator.word.sql - pop: true - - match: (?=\S) - pop: true - like-escape-character-any: - - match: (\')([^'])(\') - captures: - 0: meta.string.escape.sql string.quoted.single.sql - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: true - - match: (?=\S) - pop: true - like-escape-character-caret: - - match: (\')(\^)(\') - captures: - 0: meta.string.escape.sql string.quoted.single.sql - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: true - - match: (?=\S) - fail: like-strings-branch - like-escape-character-slash: - - match: (\')(\\)(\') - captures: - 0: meta.string.escape.sql string.quoted.single.sql - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: true - - match: (?=\S) - fail: like-strings-branch diff --git a/SQL/Symbol List.tmPreferences b/SQL/Symbol List.tmPreferences new file mode 100644 index 0000000000..0c25d4e279 --- /dev/null +++ b/SQL/Symbol List.tmPreferences @@ -0,0 +1,12 @@ + + + + scope + source.sql entity.name.struct + settings + + showInSymbolList + 1 + + + diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax new file mode 100644 index 0000000000..4e3df8fc45 --- /dev/null +++ b/SQL/TSQL.sublime-syntax @@ -0,0 +1,1058 @@ +%YAML 1.2 +--- +name: T-SQL +scope: source.sql.tsql +version: 2 + +extends: Packages/SQL/SQL (basic).sublime-syntax + +variables: + string_escape: (?:'') + simple_identifier_break: (?![\w#@]) + + additional_toplevel_reserved: |- + (?xi: backup | begin | break | bulk | continue | declare | else | end + | exec(?:ute)? | for | go | if | insert | merge | on | print | raiserror + | return | throw | use | waitfor | when | while | with ) + + identifier_for_lookahead: |- + (?x: + (?:(?:\b\w+|\[[^]]+\])\.)* + (?:\b\w+|\[[^]]+\]) + ) + + ddl_target_function: |- + (?xi: proc(?:edure)? | func(?:tion)? ) + + # types + + enclosed_type_begin: \[ + enclosed_type_end: \] + + simple_types: |- + (?xi: bigint | bit | float | int | real | smallint | tinyint + | date | datetime | datetime2 | datetimeoffset | smalldatetime | time + | geometry | hierarchyid | image | n?text | rowversion | sql_variant + | sysname | uniqueidentifier | xml ) + types_with_optional_number: |- + (?xi: n?(?:var)?char | binary | varbinary | decimal | money | numeric ) + + builtin_user_functions: |- + (?xi: (?: current_ | session_ | system_ )? user ) + +contexts: + + sql: + - meta_prepend: true + - include: declare-statements + +###[ DECLARE STATEMENTS ]###################################################### + + declare-statements: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.sql + push: inside-declaration + + inside-declaration: + - match: '{{simple_identifier}}(?=\s+(?i:cursor)\b)' + scope: meta.cursor-name.sql + pop: 1 + - match: (@){{simple_identifier}} + scope: variable.other.readwrite.declaration.tsql + captures: + 1: punctuation.definition.variable.tsql + push: expect-type + - match: ',' + scope: punctuation.separator.sequence.tsql + - include: else-pop + +###[ DDL CREATE STATEMENTS ]################################################### + + create-statements: + - match: \b(?i:create(?:\s+or\s+alter)?)\b + scope: keyword.other.ddl.sql + push: + - create-meta + - create-target + + create-target: + - meta_prepend: true + # modifiers + - match: \b(?i:unique|clustered|nonclustered)\b + scope: keyword.other.ddl.sql + - include: create-sequence + + expect-function-characteristics: + - meta_prepend: true + - include: target-options + + create-other-args: + - meta_prepend: true + - match: \b(?i:without\s+\w+)\b + scope: storage.modifier.tsql + + create-sequence: + - match: \b(?i:sequence)\b + scope: keyword.other.ddl.sql + set: + - create-sequence-args + - expect-other-creation-name + - create-other-condition + + create-sequence-args: + - match: \b(?i:as)\b + scope: keyword.context.block.sql + push: + - expect-type + - match: \b(?i:START\s+WITH|INCREMENT\s+BY|(?:NO\s+)?(?:MINVALUE|MAXVALUE|CYCLE|CACHE))\b + scope: keyword.other.ddl.basic + - include: create-common-args + + create-table-args: + - meta_prepend: true + - match: (?=\b(?i:as)\b) + pop: 1 + +###[ DDL STATEMENT PROTOTYPES ]################################################ + + alter-common: + - meta_prepend: true + - include: with-options + - match: \b(?i:(add)\s+(member))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - expect-user-name + + alter-table-args: + - meta_prepend: true + - match: \b(?i:with\s+check\b) + scope: keyword.other.ddl.tsql + + target-options: + - meta_prepend: true + - include: with-table-options + +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - meta_append: true + - match: \b(?i:bulk\s+insert)\b + scope: keyword.other.tsql + - match: \b(?i:insert)\b + scope: keyword.other.dml.sql + push: expect-table-name + - match: \b(?i:into)\b(?!\s*@) + scope: keyword.other.dml.tsql + push: expect-table-name + - match: \b(?i:into)\b + scope: keyword.other.tsql + - match: \b(?i:off)\b + scope: keyword.other.tsql + - match: \b(?i:for\s+xml)\b + scope: keyword.other.tsql + push: for-xml + - match: \b(?i:option)\b + scope: keyword.other.dml.tsql + push: maybe-with-group + - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b + scope: keyword.other.sql + push: expect-cursor-name + - match: \b(?i:merge(?:\s+into)?)\b + scope: keyword.other.tsql + push: + - maybe-table-alias + - expect-table-name + - match: \b(?i:using)\b # note: maybe valid only in merge statements + scope: keyword.context.resource.tsql + push: table-name-or-subquery + - match: \b(?i:on)\b + scope: keyword.control.conditional.sql + # - match: \b(?i:set)\b + # scope: keyword.other.dml.tsql + # push: maybe-transaction-isolation-level + - include: top + + dml-delete: + - meta_prepend: true + - include: top + + dml-update: + - meta_prepend: true + - include: top + + join-expressions: + - meta_append: true + - match: \b(?i:(?:(?:cross|outer)\s+)?apply)\b + scope: keyword.other.dml.sql + push: table-name-or-subquery + + top: + - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? + captures: + 1: keyword.other.dml.tsql + 2: meta.group.tsql punctuation.section.parens.begin.tsql + 3: meta.group.tsql meta.number.integer.decimal.tsql constant.numeric.value.tsql + 4: meta.group.tsql punctuation.section.parens.end.tsql + 5: keyword.other.dml.tsql + + for-xml: + - match: \b(?i:raw|auto|elements|root|path)\b + scope: keyword.other.tsql + - match: \b(?:XSINIL|XMLSCHEMA)\b # case sensitive?! TODO: need to check + scope: keyword.other.tsql + - match: (?=\)) + pop: 1 + - include: expressions + - include: else-pop + +###[ DML SET STATEMENTS ]###################################################### + + set-target: + - meta_prepend: true + - match: \b(?i:nocount|ansi_nulls|quoted_identifier|xact_abort|ansi_warnings|noexec|showplan_(?:all|text|xml))\b + scope: constant.language.switch.tsql + - match: \b(?i:identity_insert)\b + scope: constant.language.switch.tsql + push: expect-table-name + - match: \b(?i:transaction\s+isolation\s+level)\b + scope: constant.language.switch.tsql + set: transaction-isolation-level + - match: \b(?i:deadlock_priority)\b + scope: constant.language.switch.tsql + set: deadlock-priority + - include: onoff-constants + - include: variables + - include: augmented-assignment-operators + - include: operators + - match: ',' + scope: punctuation.separator.sequence.tsql + + transaction-isolation-level: + - match: \b(?i:READ\s+UNCOMMITTED|READ\s+COMMITTED|REPEATABLE\s+READ|SNAPSHOT|SERIALIZABLE)\b + scope: constant.language.tsql + pop: 1 + - match: (?=\S) + pop: 1 + + deadlock-priority: + - match: \b(?i:low|normal|high)\b + scope: constant.language.tsql + pop: 1 + - include: else-pop + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: + - meta_prepend: true + # context keywords + - include: cte-with + - match: \b(?i:(?:begin|commit|rollback|save)\s+tran(?:saction)?)\b + scope: keyword.context.tsql + - match: \b(?i:use)\b + scope: keyword.context.tsql + push: expect-database-name + # control flow keywords + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.tsql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.tsql + - match: \b(?i:begin|end)\s+(?i:try|catch)\b + scope: keyword.control.exception.tsql + - match: \b(?i:while)\b + scope: keyword.control.loop.tsql + - match: \b(?i:begin)\b + scope: keyword.control.flow.begin.tsql + - match: \b(?i:break)\b + scope: keyword.control.flow.break.tsql + - match: \b(?i:continue)\b + scope: keyword.control.flow.continue.tsql + - match: \b(?i:end)\b + scope: keyword.control.flow.end.tsql + - match: \b(?i:exec(?:ute)?)\b + scope: keyword.control.flow.execute.tsql + push: [expect-function-name, execute-args] + - match: \b(?i:go)\b + scope: keyword.control.flow.go.tsql + - match: \b(?i:goto)\b + scope: keyword.control.flow.goto.tsql + push: expect-label-name + - match: \b(?i:return)\b + scope: keyword.control.flow.return.tsql + - match: \b(?i:throw)\b + scope: keyword.control.flow.throw.tsql + - match: \b(?i:waitfor)\b + scope: keyword.control.flow.waitfor.tsql + push: waitfor-args + # builtin funtions + - match: \b(?i:print)\b + scope: support.function.tsql + - match: (?=\b(?i:raiserror)\b) + push: raiserror-args + # other keywords + - match: \b(?i:backup(?:\s+database)?)\b # https://docs.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql?view=sql-server-ver15 + scope: keyword.other.tsql + - match: \b(?i:to)\b + scope: keyword.other.tsql + - match: \b(?i:disk|tape|url)\b + scope: keyword.other.tsql + - match: \b(?i:pivot|unpivot)\b + scope: keyword.other.tsql + push: [maybe-table-alias, maybe-group] + - match: \b(?i:for)\b + scope: keyword.other.tsql + - match: \b\w+(?=::) + scope: storage.type.tsql + - match: \b(\w+)(:) + captures: + 1: entity.name.label.tsql + 2: punctuation.definition.label.tsql + + execute-args: + - include: pop-on-top-level-reserved-word + - include: assignment-operators + - include: expressions + - include: else-pop + + raiserror-args: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: raiserror-options + - include: pop-on-top-level-reserved-word + - include: expressions + + raiserror-options: + - match: \b(?i:nowait|log|seterror)\b + scope: keyword.other.tsql + - include: else-pop + + waitfor-args: + - match: \b(?i:delay|time)\b + scope: storage.type.tsql + pop: 1 + - include: else-pop + +###[ CTE WITH STATEMENTS ]##################################################### + + cte-with: + - match: \b(?i:with)\b(?=\s*(?:\[\w+\]|\w+)\s*\() + scope: keyword.other.dml.sql + push: + - cte-as + - maybe-column-name-list + - expect-cte-table-name + - match: \b(?i:with)\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) + scope: keyword.other.dml.sql + push: + - cte-as + - expect-cte-table-name + + cte-as: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.cte.tsql + - include: pop-on-top-level-reserved-word + - match: ',' + scope: punctuation.separator.sequence.cte.tsql + push: + - maybe-column-name-list + - expect-cte-table-name + - include: expressions + +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_prepend: true + - include: with-table-options + - include: like-expressions + - match: \b(?i:output)\b + scope: storage.modifier.output.tsql + - match: \b(?i:over|partition\s+by)\b + scope: keyword.other.sql + - match: \b(?i:unbounded|preceding|following|current\s+row|(?:rows|range)\s+between|next\s+value)\b + scope: keyword.other.sql + - match: \b(?i:cursor)\b + scope: support.type.tsql + push: inside-cursor-declaration + - match: \b(?i:when\s+(?:not\s+)?matched)\b + scope: keyword.control.conditional.case.sql + push: merge-condition + - match: \b(?i:include)\b + scope: keyword.other.sql + - match: \b(?i:within\s+group)\b + scope: keyword.other.tsql + - match: \b(?i:at\s+time\s+zone)\b + scope: storage.modifier.tsql + + built-in-scalar-function-calls: + - meta_append: true + - match: \b(?i:cast)\b + scope: support.function.tsql + push: cast-arguments + - match: \b((?i:convert))\s*(\() + scope: meta.function-call.sql + captures: + 1: support.function.scalar.sql + 2: meta.group.sql punctuation.section.arguments.begin.sql + push: + - inside-convert-arguments + - expect-type + - match: \b(?i:getdate)(?=\s*\() + scope: support.function.scalar.sql + push: function-call-arguments + + cast-arguments: + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.arguments.begin.sql + set: inside-cast-arguments + - include: else-pop + + inside-cast-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: \b(?i:as)\b + scope: keyword.operator.assignment.tsql + push: expect-type + - include: expressions-or-column-names + + inside-convert-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.arguments.sql + - include: expressions-or-column-names + + inside-function-call-arguments: + - meta_prepend: true + - include: datepart-units + + user-defined-function-calls: + - meta_append: true + - match: (?={{identifier_for_lookahead}}\s*\() + push: + - function-call-arguments + - function-name + - single-identifier + + function-name: + - meta_include_prototype: false + - meta_content_scope: variable.function.tsql + - include: immediately-pop + + inside-cursor-declaration: + - meta_content_scope: meta.cursor-declaration.tsql + - match: |- + \b(?xi: DYNAMIC | FAST_FORWARD | FORWARD_ONLY | KEYSET | OPTIMISTIC + | READ_ONLY | SCROLL | SCROLL_LOCKS | STATIC | TYPE_WARNING )\b + scope: storage.modifier.tsql + - match: \b(?i:for)\b + scope: keyword.other.tsql + set: cursor-select-statement + - include: else-pop + + cursor-select-statement: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:select)\b + scope: keyword.other.dml.sql + set: inside-cursor-select-statement + - include: else-pop + + inside-cursor-select-statement: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:for)\b + scope: keyword.other.tsql + set: after-cursor-select-statement + - match: (?=\b(?i:open)\b) + pop: 1 + - include: sql + + after-cursor-select-statement: + - meta_scope: meta.cursor-declaration.tsql + - match: \b(?i:read\s+only|update(?:\s+of)?)\b + scope: storage.modifier.tsql + pop: 1 + - include: else-pop + + merge-condition: + - match: \b(?i:by\s+(?:source|target))\b + scope: keyword.other.tsql + - match: \b(?i:then)\b + scope: keyword.other.tsql + pop: 1 + - include: values-or-expressions + - include: pop-on-top-level-reserved-word + + values-or-expressions: + - include: dml-statements + - include: expressions + +###[ COLUMN EXPRESSIONS ]###################################################### + + maybe-column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: + - maybe-with-table-options + - maybe-filegroup + - inside-column-declaration-list + - include: else-pop + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:rowguidcol|clustered|nonclustered)\b + scope: storage.modifier.tsql + - match: \b(?i:period\s+for\s+system_time)\b + scope: storage.modifier.tsql + +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-parameters: + - meta_prepend: true + - match: (@){{simple_identifier}} + scope: variable.parameter.tsql + captures: + 1: punctuation.definition.variable.tsql + push: expect-type + - include: comma-separators + + expect-parameter-name: + - match: (@){{simple_identifier}} + captures: + 0: variable.parameter.sql + 1: punctuation.definition.variable.tsql + - match: \b(?i:as)\b + scope: keyword.context.tsql + - include: else-pop + +###[ WITH EXPRESSIONS ]######################################################## + + maybe-with-table-options: + - include: with-table-options + - include: else-pop + + with-table-options: + - match: \b(?i:with)\b + scope: keyword.other.dml.sql + push: maybe-with-group + + maybe-with-group: + - include: with-group + - include: else-pop + + with-group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-with-group + + inside-with-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + set: maybe-filegroup + - match: \b(?i:optimize\s+for\s+unknown)\b + scope: keyword.other.tsql + - match: \b((?i:optimize\s+for))\s*(\() + captures: + 1: keyword.other.tsql + 2: meta.group.tsql punctuation.section.group.begin.tsql + push: inside-optimize-for-group + - match: \b((?i:index|forceseek))\s*(\() + captures: + 1: keyword.other.tsql + 2: meta.group.tsql punctuation.section.group.begin.tsql + push: inside-index-names-group + - match: \b((?i:index))\s*(=) + captures: + 1: keyword.other.tsql + 2: keyword.operator.assignment.tsql + push: expect-index-name + - match: \b((?i:system_versioning))\s*(=) + captures: + 1: keyword.other.tsql + 2: keyword.operator.assignment.tsql + push: with-group-assignment + - match: \b((?i:history_table))\s*(=) + captures: + 1: keyword.other.tsql + 2: keyword.operator.assignment.tsql + push: expect-table-name + - include: with-simple-options + + with-options: + - match: \b(?i:with)\b + scope: keyword.other.dml.sql + set: with-simple-options + + with-simple-options: + - match: (?=;|\b(?i:GO|END)\b) # NOTE: we cant use the pop-on-top-level-reserved-word context here because it includes things like GRANT which are valid here + pop: true + - match: '{{simple_identifier}}' + scope: constant.language.with.tsql + - match: '=' + scope: keyword.operator.assignment.tsql + push: with-other-assignment + - include: comma-separators + + maybe-filegroup: + - match: \b(?i:on)\b(?!\s*{{identifier_for_lookahead}}\s*=) + scope: keyword.other.tsql + set: expect-filegroup-name + - include: else-pop + + inside-index-names-group: + - meta_content_scope: meta.group.tsql + - match: \) + scope: meta.group.tsql punctuation.section.group.end.tsql + pop: 1 + - include: comma-separators + - include: column-name-list + - include: literals-and-variables + - include: expect-index-names + + inside-optimize-for-group: + - meta_content_scope: meta.group.tsql + - match: \) + scope: meta.group.tsql punctuation.section.group.end.tsql + pop: 1 + - match: \b(?i:unknown)\b + scope: keyword.other.tsql + - include: expressions + + with-group-assignment: + - include: with-group + - include: onoff-constants + - include: else-pop + + with-other-assignment: + - match: (?=[,)]) + pop: 1 + - include: onoff-constants + - include: pop-on-top-level-reserved-word + - include: expressions + - match: (?=") + set: + - generic-identifier-name + - single-identifier + - match: \w+ + scope: string.unquoted.tsql + - match: (?=\[) + set: + - generic-identifier-name + - single-identifier + + generic-identifier-name: + - meta_include_prototype: false + - meta_content_scope: string.quoted.tsql + - include: immediately-pop + +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + grant: + - meta_prepend: true + - match: \b(?i:on)\b + scope: keyword.context.resource.tsql + push: qualified-identifier + - include: with-options + + user-privileges: + - meta_prepend: true + - match: \b(?i:control)\b + scope: constant.language.tsql + - match: \b(?i:from\s+external\s+provider)\b + scope: constant.language.tsql + - match: \b(?i:showplan)\b + scope: constant.language.sql + - match: \b(?i:view\s+server\s+state)\b + scope: constant.language.sql + + qualified-identifier: + # https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-transact-sql?view=sql-server-ver16#syntax + - match: \b(?i:(database|schema))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - database-name + - single-identifier + - match: \b(?i:(login|role|user))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - user-name + - single-identifier + - match: \b(?i:(\w+))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - other-name + - single-identifier + - match: (?=\S) + set: + - maybe-double-colon-accessor + - generic-identifier-name + - single-identifier + + maybe-double-colon-accessor: + - match: '::' + scope: punctuation.accessor.double-colon.tsql + set: qualified-identifier + - match: (?=\S) + pop: true + +###[ TABLE NAMES OR SUBQUERIES ]############################################### + + table-subquery: + - meta_append: true + - match: \b(?i:openxml)\b + scope: meta.table-valued-function-name.sql support.function.tsql + set: + - maybe-with-column-definition + - function-call-arguments + - match: \b(?i:(openrowset))\s*(\() + scope: meta.function-call.tsql + captures: + 1: meta.table-valued-function-name.sql support.function.tsql + 2: punctuation.section.arguments.begin.tsql + set: inside-openrowset-call + + inside-openrowset-call: + - meta_content_scope: meta.group.sql + - match: \) + scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql + set: maybe-table-alias + - match: ';' + scope: punctuation.separator.sequence.tsql + - include: inside-function-call-arguments + + table-name-fail-if-function-call: + - meta_prepend: true + - include: table-hints-without-with + + maybe-table-alias: + - meta_prepend: true + - include: table-timespecs + - include: with-table-options + - match: (?=\b(?i:unpivot|pivot)\b) + pop: 1 + + table-alias-name: + - meta_prepend: true + - match: '' + set: maybe-table-sample + + maybe-table-sample: + - include: table-hints-without-with + - include: with-table-options + - match: \b(?i:tablesample(?:\s+system)?)\b + scope: keyword.other.sql + push: + - after-tablesample-group + - maybe-table-sample-group + - include: else-pop + + maybe-table-sample-group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-tablesample-group + - include: else-pop + + inside-tablesample-group: + - meta_scope: meta.group.tablesample.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:rows|percent)\b + scope: constant.language.sql + - include: expressions + + after-tablesample-group: + - match: \b(?i:repeatable)\b + scope: constant.language.sql + pop: 1 + - include: else-pop + + table-hints-without-with: + # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments + - match: |- + (?xi) + (\() \s* + ( nolock | readuncommitted | updlock | repeatableread | serializable + | readcommitted | tablock | tablockx | paglock | rowlock | nowait + | readpast | xlock | snapshot | noexpand ) + \s* (\)) + scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql + captures: + 1: punctuation.section.group.begin.tsql + 2: constant.language.table-hint.tsql + 3: punctuation.section.group.end.tsql + + maybe-with-column-definition: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: maybe-column-declaration-list + - include: else-pop + + table-timespec-args: + - meta_prepend: true + - match: \b(?i:contained\s+in) + scope: keyword.operator.logical.tsql + set: maybe-group + +###[ TYPES ]################################################################### + + expect-type: + - meta_prepend: true + - match: \b(?i:as)\b + scope: keyword.other.tsql + set: computed-column-definition + + computed-column-definition: + - meta_content_scope: meta.computed-column-definition.tsql + - match: (?=[,)]) + pop: 1 + - match: (?=\b(?i:constraint)\b) + pop: 1 + - include: expressions-or-column-names + + built-in-type: + - meta_prepend: true + - match: |- + (?xi) + {{enclosed_type_begin}} + {{simple_types}} + {{enclosed_type_end}} + scope: storage.type.sql + pop: 1 + - match: |- + (?xi) + {{enclosed_type_begin}} + {{types_with_optional_number}} + {{enclosed_type_end}} + scope: storage.type.sql + set: optional-number-after-type + - match: |- + (?xi) + (?:{{enclosed_type_begin}}|\b) + table + (?:{{enclosed_type_end}}|\b) + scope: storage.type.sql + set: + - create-table-args + - maybe-column-declaration-list + - match: |- + (?xi) + {{types_with_optional_number}} + scope: storage.type.sql + set: optional-number-after-type + + optional-number-after-type: + - match: |- + (?x) + \s* + (\()\s* + (?i:(\d+)|(max)) + \s*(?:(,)\s*(\d+))? + (\)) + scope: storage.type.sql + captures: + 1: punctuation.section.group.begin.tsql + 2: constant.numeric.sql + 3: constant.language.max.sql + 4: punctuation.separator.sequence.sql + 5: constant.numeric.sql + 6: punctuation.section.group.end.tsql + pop: 1 + - include: else-pop + + inside-user-type: + - meta_prepend: true + - include: variables + + after-type: + - meta_prepend: true + - match: \b(?i:generated\s+always\s+as\s+row\s+(?:start|end)(?:\s+hidden)?)\b + scope: keyword.other.tsql + - match: \b(?i:encrypted\s+with)\b + scope: storage.modifier.tsql + set: + - maybe-table-alias + - maybe-with-group + - match: \b(?i:readonly)\b + scope: storage.modifier.tsql + - include: collate-expressions + +###[ IDENTIFIERS ]############################################################# + + expect-cte-table-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [cte-table-name, single-identifier] + + cte-table-name: + - meta_include_prototype: false + - meta_content_scope: meta.cte-table-name.sql + - include: immediately-pop + + expect-cursor-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [cursor-name, single-identifier] + + cursor-name: + - meta_include_prototype: false + - meta_content_scope: meta.cursor-name.sql + - include: immediately-pop + + expect-filegroup-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [filegroup-name, single-identifier] + + filegroup-name: + - meta_include_prototype: false + - meta_content_scope: meta.filegroup-name.tsql + - include: immediately-pop + + expect-label-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [label-name, single-identifier] + + label-name: + - meta_include_prototype: false + - meta_content_scope: meta.label-name.sql + - include: immediately-pop + + maybe-identifier-accessor: + - meta_prepend: true + - match: \s*(\.{2,})\s* + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier + + identifier-part: + - meta_prepend: true + - match: \b(?i:inserted|deleted)(\.) + scope: constant.language.table.tsql + captures: + 1: punctuation.accessor.dot.tsql + - include: square-bracketed-identifier-part + + square-bracketed-identifier-part: + - match: \[ + scope: punctuation.definition.identifier.begin.sql + set: inside-square-bracketed-identifier-part + + inside-square-bracketed-identifier-part: + # note: may contain foreign variable interpolation + - match: \] + scope: punctuation.definition.identifier.end.sql + pop: 1 + + inside-simple-identifier-part: + - meta_prepend: true + - include: variables + - match: \# + scope: punctuation.definition.variable.tsql + +###[ LITERALS ]################################################################ + + literals-and-variables: + - meta_prepend: true + - include: variables + + onoff-constants: + - match: \b(?i:on|off)\b + scope: constant.language.boolean.tsql + + numbers: + - meta_prepend: true + - match: (0x)(\h+) + scope: meta.number.integer.hexadecimal.tsql + captures: + 1: constant.numeric.base.tsql + 2: constant.numeric.value.tsql + + strings: + - meta_append: true + - match: N' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-string + + variables: + - match: (@){{simple_identifier}} + scope: variable.other.readwrite.sql + captures: + 1: punctuation.definition.variable.sql + push: maybe-variable-scoped-function-call + - match: |- + (?xi)(@@) + (?: cursor_rows | connections | cpu_busy | datefirst | dbts | error + | fetch_status | identity | idle | io_busy | langid | language + | lock_timeout | max_connections | max_precision | nestlevel | options + | packet_errors | pack_received | pack_sent | procid | remserver + | rowcount | servername | servicename | spid | textsize | timeticks + | total_errors | total_read | total_write | trancount | version )\b + scope: support.variable.global.sql + captures: + 1: punctuation.definition.variable.sql + - match: '\$action\b' # has to be lowercase + scope: variable.language.tsql + - match: \b(?i:default)\b + scope: variable.language.tsql + + maybe-variable-scoped-function-call: + - match: \s*\.(?=\s*\w+\s*\() + scope: punctuation.accessor.dot.tsql + - include: immediately-pop + + datepart-units: + # https://learn.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql?view=sql-server-ver16 + - match: \b(?i:DAY|MONTH|YEAR|QUARTER|DAYOFYEAR|WEEK|HOUR|MINUTE|SECOND|MILLISECOND|MICROSECOND|NANOSECOND)\b(?!\s*\.) + scope: constant.language.tsql + - match: \b(?i:D?D|YYYY|YY?|Q?Q|M?M|DY|WK|WW|HH|MI|N|SS?|MS|MCS|NS)\b(?!\s*\.) + scope: constant.language.tsql + +###[ LIKE EXPRESSIONS ]######################################################## + inside-like-single-quoted-string: + - meta_append: true + - match: |- + (?x) + (\[)(\^)? + (?:.|[^]'-]+?) + (?:(-)[^]'-]*)? + (\]) + scope: meta.set.like.sql + captures: + 1: keyword.control.set.begin.sql + 2: keyword.control.set.negation.sql + 3: constant.other.range.sql + 4: keyword.control.set.end.sql + +###[ OPERATORS ]############################################################### + + operators: + - meta_append: true + - match: '%' + scope: keyword.operator.arithmetic.tsql + - match: '::' + scope: punctuation.accessor.double-colon.tsql + + augmented-assignment-operators: + - match: '[-+/*%^|]=' + scope: keyword.operator.assignment.tsql diff --git a/SQL/syntax_test_sql.sql b/SQL/syntax_test_sql.sql deleted file mode 100644 index 59ee2e7771..0000000000 --- a/SQL/syntax_test_sql.sql +++ /dev/null @@ -1,312 +0,0 @@ --- SYNTAX TEST "Packages/SQL/SQL.sublime-syntax" - -SELECT 'Foo Bar'; --- ^^^^^^^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ punctuation.definition.string.end --- ^ punctuation.terminator.statement - string - -SELECT 'Foo '' Bar'; --- ^^ constant.character.escape.sql - -SELECT "My "" Crazy Column Name" FROM my_table; --- ^^ constant.character.escape.sql - -SELECT "My -- Crazy Column Name" FROM my_table; --- ^^ - comment - punctuation - -SELECT "My /* Crazy Column Name" FROM my_table; --- ^^ - comment - punctuation - - -;CREATE TABLE foo (id INTEGER PRIMARY KEY); - -- <- keyword.other.create ---^^^^^ keyword.other.create --- ^^^^^ keyword.other --- ^^^ entity.name.function --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name.function - -create table some_schema.test2( id serial ); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^^^^^^^^^^^^ - entity.name.function --- ^ punctuation.accessor.dot --- ^^^^^ entity.name.function --- ^^^^^^^^^^^^^^ - entity.name.function - -create table some_schema . test2 ( id serial ); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^ - entity.name --- ^ punctuation.accessor.dot --- ^^^^^ entity.name.function --- ^^^^^^^^^^^^^^^ - entity.name.function - -create table "testing123" (id integer); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^ - entity.name.function --- ^^^^^^^^^^ entity.name.function --- ^^^^^^^^^^^^^^^^ - entity.name.function - -create table `dbo`."testing123" (id integer); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^^^^^^^ - entity.name.function --- ^ punctuation.accessor.dot --- ^^^^^^^^^^ entity.name.function --- ^^^^^^^^^^^^^^^^ - entity.name.function - -create table IF NOT EXISTS `testing123` ( --- ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.toc-list --- ^^ keyword.control.flow --- ^^^ keyword.operator.logical --- ^^^^^^ keyword.operator.logical - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, --- ^^^^^^^^^ storage.type.sql --- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql --- ^^^^^^^^^ storage.modifier.sql - `col` bool DEFAULT FALSE, --- ^^^^ storage.type.sql --- ^^^^^^^ storage.modifier.sql --- ^^^^^ constant.language.boolean.false.sql --- ^ punctuation.separator.sequence - `fkey` INT UNSIGNED NULL REFERENCES test2(id), --- ^^^^^^^^^^ storage.modifier.sql - `version` tinytext DEFAULT NULL COMMENT 'important clarification', --- ^^^^^^^^ storage.type.sql - `percentage` float DEFAULT '0', - UNIQUE KEY `testing123_search` (`col`, `version`), --- ^^^^^^^^^^ storage.modifier.sql - KEY `testing123_col` (`col`), --- ^^^ storage.modifier.sql - FULLTEXT KEY `testing123_version` (`version`) -) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; - -create table fancy_table ( - id SERIAL, --- ^^^^^^ storage.type.sql - foreign_id integer, --- ^^^^^^^ storage.type.sql - myflag boolean DEFAULT false, --- ^^^^^^^ storage.type.sql - mycount double precision DEFAULT 1, --- ^^^^^^^^^^^^^^^^^ storage.type.sql - fancy_column character varying(42) DEFAULT 'nice'::character varying, --- ^^^^^^^^^^^^^^^^^^ storage.type.sql - mytime timestamp(3) without time zone DEFAULT now(), --- ^^^^^^^^^^^^^^^^^ storage.type.sql - mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, --- ^^^^^^^^^^^^^^^^^^^ storage.type.sql - primary key (id), --- ^^^^^^^^^^^ storage.modifier.sql - UNIQUE (foreign_id), - CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) --- ^^^^^^^^^^ storage.modifier.sql --- ^^^^^ storage.modifier.sql -); - -CREATE INDEX ON fancy_table(mytime); --- ^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql --- ^^^^^^^^^^^ entity.name.function.sql - -CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); --- ^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql - -CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; --- ^^^^^^^^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql --- ^^^^^^^^^^^ entity.name.function.sql --- ^^^^^ keyword.other.DML.sql --- ^^ keyword.operator.logical.sql --- ^^^^ constant.language.null.sql - -create fulltext index if not exists `myindex` ON mytable; --- ^^^^^^^^^^^^^^ keyword.other.sql - -ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; --- ^^^ keyword.other.add.sql --- ^^^^^^ keyword.other.sql --- ^^^^^^^^ storage.type.sql - -ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); --- ^^^^ storage.type.sql - -DROP TABLE IF EXISTS testing123; --- <- meta.drop.sql keyword.other.create.sql --- ^^^^^^ keyword.operator.logical.sql - -select * -from some_table -where exists(select * from other_table where id = some_table.id) --- ^^^^^^ keyword.operator.logical - -SELECT -( -SELECT CASE field -USING a --- <- keyword.other.DML - WHEN 1 - THEN -- comment's say that --- ^ comment.line.double-dash - EXISTS( - select 1) - ELSE NULL - END -) as result - - -/* --- <- comment.block punctuation.definition.comment.begin -This is a -multiline comment --- ^^^^^^^^^^^^^^^ source.sql comment.block.sql -*/ --- <- comment.block punctuation.definition.comment.end - -/** - * --- ^ punctuation.definition.comment.sql -*/ - -select - - - <=> --- ^^^ keyword.operator.comparison.sql - -SELECT *, --- ^^^ keyword.other.DML.sql --- ^ constant.other.wildcard.asterisk.sql - f.id AS database_id --- ^^ keyword.operator.assignment.alias.sql -FROM foo -WHERE f.a IS NULL --- ^^ keyword.other.DML.sql --- ^^ keyword.operator.logical.sql --- ^^^^ constant.language.null.sql - AND f.b IS NOT NULL --- ^^^ keyword.operator.logical.sql --- ^^ keyword.operator.logical.sql --- ^^^ keyword.operator.logical.sql --- ^^^^ constant.language.null.sql - - -SELECT columns FROM table WHERE - column LIKE '%[[]SQL Server Driver]%' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^^^ meta.set.like --- ^ keyword.control.set.begin --- ^ keyword.control.set.end --- ^^^^^^^^^^^^^^^^^^ - constant - keyword --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE '%[SQL Server Driver]%' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^^^^^ meta.set.like --- ^ keyword.control.set.begin --- ^ keyword.control.set.end --- ^^^^^^^^^^^^^^^ - constant - keyword --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE '%[^a-f]%' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^^^^^^ meta.set.like --- ^ keyword.control.set.begin --- ^ keyword.control.set.negation --- ^ constant.other.range --- ^ keyword.control.set.end --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE 'hello_world' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE '%\[SQL Server Driver]^%\__' ESCAPE '\' --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ - constant --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ keyword.operator.wildcard --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end - -SELECT columns FROM table WHERE - column LIKE '%\[SQL Server Driver]^%\__' --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ - constant --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ keyword.operator.wildcard - ESCAPE '\' --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end - -SELECT columns FROM table WHERE - column LIKE '%\^[SQL Server Driver]^%_^_' ESCAPE '^' --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^ - constant --- ^^ constant.character.escape --- ^^ constant.character.escape --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end - -SELECT columns FROM table WHERE - column LIKE '%\^[SQL Server Driver]^%_^_\_{{--' ESCAPE '{' -- uncatered for escape char, scope operators as though unescaped --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - constant --- ^^^^^^^^^^^^^^^^^^^ meta.set.like --- ^^^^^^^^^^^ - meta.set --- ^^ keyword.operator.wildcard --- ^ keyword.operator.wildcard --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^ - comment --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end --- ^^ comment.line.double-dash punctuation.definition.comment diff --git a/SQL/tests/indentation/syntax_test_indentation_tsql.sql b/SQL/tests/indentation/syntax_test_indentation_tsql.sql new file mode 100644 index 0000000000..1816cead2a --- /dev/null +++ b/SQL/tests/indentation/syntax_test_indentation_tsql.sql @@ -0,0 +1,58 @@ +-- SYNTAX TEST reindent "Packages/SQL/TSQL.sublime-syntax" +SELECT * +FROM ( + SELECT * + FROM a + INNER JOIN b ON a.ID = b.ID +) alias +WHERE 1 = 1 +GO + +BEGIN + INSERT INTO a + VALUES (123, 456) +END + +BEGIN + INSERT INTO a + VALUES (123, 456) +GO + INSERT INTO b + VALUES (123, 456) +END + +SELECT +a, +b, +c +FROM foo + +SELECT a +,b +,c +FROM foo + +CREATE TABLE hello ( + field1 int, + field2 nvarchar(50) +) + +CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( + some_column ASC +) + +SET @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + +BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) +END + +SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 + +'no indentation increase when an unclosed open paren is in a string(' +BEGIN + 'no indentation decrease when a close paren with no matching open paren on the same line is in a string)' + null + -- no indentation increase when an unclosed open paren is in a comment ( + --no indentation decrease when a close paren with no matching open paren on the same line is in a comment ) + null +END diff --git a/SQL/tests/symbols/syntax_test_symbols_tsql.sql b/SQL/tests/symbols/syntax_test_symbols_tsql.sql new file mode 100644 index 0000000000..ad0ec2e548 --- /dev/null +++ b/SQL/tests/symbols/syntax_test_symbols_tsql.sql @@ -0,0 +1,24 @@ +-- SYNTAX TEST "Packages/SQL/TSQL.sublime-syntax" + +CREATE TABLE hello ( + -- @@@@@ definition + field1 int, + field2 nvarchar(50) +) + +CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( + -- @@@@@@@@@@@@@ definition + some_column ASC +) + +SET @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) +-- @@@@@@@ reference +-- @@@@@@@ reference + +BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) + -- @@@@@@@@@ reference +END + +SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 +-- @@@@@@@@ reference +-- @@@@@@ reference diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql new file mode 100644 index 0000000000..1944904a9b --- /dev/null +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -0,0 +1,582 @@ +-- SYNTAX TEST "Packages/SQL/Cassandra.sublime-syntax" + +CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}; +--^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +--^^^^ keyword.other.ddl +-- ^^^^^^^^ keyword.other +-- ^^^^^^^^^^ entity.name.struct.other +-- ^^^^ keyword.other +-- ^ keyword.operator +-- ^ punctuation.section.braces.begin +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.separator.key-value +-- ^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.key-value +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.braces.end +-- ^ punctuation.terminator.statement + +select someid, token(someid), something +--^^^^ keyword.other.dml +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^ meta.function-call support.function +-- ^ meta.function-call meta.group punctuation.section.arguments.begin +-- ^^^^^^ meta.function-call meta.group meta.column-name +-- ^ meta.function-call meta.group punctuation.section.arguments.end +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name +from something_by_someid +--^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^ meta.table-name +where token(someid) >= token(d821d7d8-8265-402e-9a72-c61ab8473ab6) +--^^^ keyword.other.dml +-- ^^^^^^^^^^^^^ meta.function-call +-- ^^^^^ support.function +-- ^^^^^^^^ meta.group +-- ^ punctuation.section.arguments.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.arguments.end +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^ support.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid +-- ^ punctuation.section.arguments.end +-- ^ - meta +and token(someid) <= token(cf0acefc-ccff-42a0-8753-65d82e9c9b0f) +limit 2000; +-- <- keyword.other.dml +--^^^ keyword.other.dml +-- ^^^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.terminator.statement + +select count(someid) +from something_by_someid +where something = 'abc' +-- ^^ keyword.other.dml +-- ^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^ string.quoted.single +limit 2000 +allow filtering; +-- ^^^^^^^^^^^^ keyword.other.dml +-- ^ punctuation.terminator.statement + +insert into something_by_countrycode (someid, countrycode) values (:someid, :countrycode); +-- ^^^^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^ keyword.other.dml.II +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^ variable.other.constant +-- ^ punctuation.separator.sequence +-- ^ punctuation.definition.variable +-- ^^^^^^^^^^^ variable.other.constant +-- ^ punctuation.terminator.statement + +CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct +-- ^ meta.group.table-columns punctuation.section.group.begin + userid uuid, +-- ^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.separator.sequence + permissions frozen>, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^^^ - meta.generic +-- ^^^^ meta.generic.cql - meta.generic meta.generic +-- ^^^^^^ meta.generic.cql meta.generic.cql - meta.generic meta.generic meta.generic +-- ^ meta.generic.cql - meta.generic meta.generic +-- ^ - meta.generic +-- ^^^^^^ storage.type +-- ^ punctuation.definition.generic.begin +-- ^^^ storage.type +-- ^ punctuation.definition.generic.begin +-- ^^^^ storage.type +-- ^^ punctuation.definition.generic.end +-- ^ punctuation.separator.sequence + storage tuple>>, +-- ^^^^^ - meta.generic +-- ^^^^ meta.generic.cql - meta.generic meta.generic +-- ^^^^^^^^^^ meta.generic.cql meta.generic.cql - meta.generic meta.generic meta.generic +-- ^^^^^^^^^ meta.generic.cql meta.generic.cql meta.generic.cql +-- ^ meta.generic.cql meta.generic.cql - meta.generic meta.generic meta.generic +-- ^ meta.generic.cql - meta.generic meta.generic +-- ^ - meta.generic +-- ^^^^^ storage.type.cql +-- ^ punctuation.definition.generic.begin.cql +-- ^^^ storage.type.cql +-- ^ punctuation.definition.generic.begin.cql +-- ^^^^ storage.type.sql +-- ^ punctuation.separator.sequence.cql +-- ^^^ storage.type.cql +-- ^ punctuation.definition.generic.begin.cql +-- ^^^^^^^ support.type.sql +-- ^^^ punctuation.definition.generic.end.cql +-- ^ punctuation.separator.sequence.sql + PRIMARY KEY(userid) +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^^^^^^^^^^ storage.modifier +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^ meta.group.partition-key meta.column-name +-- ^ meta.group.partition-key punctuation.section.group.end +); +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end + +CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( + userid uuid, + other_id uuid, + test text, + PRIMARY KEY(userid, other_id) +-- ^^^^^^^^^^^ meta.statement.create meta.group.table-columns storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.group.partition-key meta.column-name +-- ^^^^^^^^^^^ - meta.group.partition-key +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^^ meta.group.table-columns meta.group meta.column-name +-- ^ punctuation.section.group.end +); +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end +CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( + userid uuid, + other_id uuid, + test text, + PRIMARY KEY ((userid), other_id) +-- ^^^^^^^^^^^ meta.statement.create meta.group.table-columns storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^^^ meta.group.partition-key +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^^ - meta.group.partition-key +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.group.table-columns meta.group meta.column-name +-- ^ punctuation.section.group.end +); +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end +CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( + userid uuid, + other_id timeuuid, +-- ^^^^^^^^ meta.column-name +-- ^^^^^^^^ storage.type +-- ^ punctuation.separator.sequence + test int, + PRIMARY KEY ((userid, other_id), test) +-- ^^^^^^^^^^^ meta.statement.create meta.group.table-columns storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^^ meta.group.partition-key +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^ - meta.group.partition-key +-- ^ punctuation.separator.sequence +-- ^^^^ meta.group.table-columns meta.group meta.column-name +-- ^ punctuation.section.group.end +); +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end + +CREATE TABLE IF NOT EXISTS date_by_userid ( + userid uuid PRIMARY KEY, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence + `date` timestamp +-- ^^^^^^ meta.column-name +-- ^^^^^^^^^ storage.type +); + + +DROP TABLE IF EXISTS userpermissions_by_userid; +-- <- meta.statement.drop.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +--^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^ keyword.other.ddl +-- ^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^ entity.name.struct.other +-- ^^ keyword.context.block + SELECT * +-- ^^^^^^ keyword.other.dml +-- ^ constant.other.wildcard.asterisk + FROM foo + WHERE bar IS NOT NULL + PRIMARY KEY (foo_id, bar_id) +-- ^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.group.end + WITH comment = 'allow querying by relationship more easily'; +-- ^^^^ keyword.other +-- ^^^^^^^ string.unquoted +-- ^ keyword.operator +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.terminator.statement + +CREATE TYPE user_defined_type ( +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +--^^^^ keyword.other.ddl +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^ entity.name.type +-- ^ meta.group punctuation.section.group.begin + type1 timestamp, +-- ^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^ storage.type +-- ^ punctuation.separator.sequence + type2 text, + type3 counter, +-- ^^^^^ meta.column-name +-- ^^^^^^^ storage.type + type4 boolean, +-- ^^^^^ meta.column-name +-- ^^^^^^^ storage.type + type5 blob, +-- ^^^^^ meta.column-name +-- ^^^^ storage.type + type6 inet); +-- ^^^^^ meta.column-name +-- ^^^^ storage.type + +INSERT INTO something_by_someid (someid, somebool, somemap) +VALUES ( + 583395ca-0845-4517-b0f7-97bb0ea86b53, + false, + {77a969b4-378a-4fb0-b531-83404ee3c395:{id:22f7244c-c6d7-4bd7-aeac-a886c4242cd8,sometext:'text here',empty:{}}} + -- <- meta.braces.cql punctuation.section.braces.begin.cql + --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.cql - meta.braces meta.braces + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.cql meta.braces.cql + -- ^ meta.braces.cql - meta.braces meta.braces + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid + -- ^ punctuation.separator.key-value + -- ^ punctuation.section.braces.begin + -- ^^ meta.mapping.key string.unquoted + -- ^ punctuation.separator.key-value + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid + -- ^ punctuation.separator.sequence + -- ^^^^^^^^ meta.mapping.key string.unquoted + -- ^ punctuation.separator.key-value + -- ^^^^^^^^^^^ string.quoted.single + -- ^ punctuation.separator.sequence + -- ^^^^^ meta.mapping.key string.unquoted + -- ^ punctuation.separator.key-value + -- ^ punctuation.section.braces.begin + -- ^^^ punctuation.section.braces.end +); + +INSERT INTO something_by_someid (someid, someset) +VALUES (22f7244c-c6d7-4bd7-aeac-a886c4242cd8,{'item1','item2','item3'}); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.cql +-- ^ punctuation.section.braces.begin +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.section.braces.end +-- ^ meta.group punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE TABLE IF NOT EXISTS someentity_by_somefield ( + entityid uuid, + datecreated timestamp, + somefield int, + anotherfield text +PRIMARY KEY (entityid, datecreated, somefield) +) WITH CLUSTERING ORDER BY (datecreated DESC, somefield ASC); +--^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other +-- ^^^^^^^^^^ keyword.other +-- ^^^^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^ keyword.other.order +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name +-- ^^^ keyword.other.order +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +ALTER TABLE someentity_by_somefield add usefulfield text; +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.terminator.statement + +ALTER TABLE someentity_by_somefield + add usefulfield text; +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.alter +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.terminator.statement + +ALTER TABLE someentity_by_somefield + DROP unnecessryfield; +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.alter +-- ^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.terminator.statement + + +select * +from test_by_example +join fred -- there are no joins in CQL +-- <- - keyword +--^^ - keyword + +USE killrvideo; +-- <- keyword.context +--^ keyword.context +-- ^^^^^^^^^^ meta.database-name +-- ^ punctuation.terminator.statement + +select uuid(), now(), * +-- ^^^^ meta.function-call support.function.scalar +-- ^ punctuation.separator.sequence +-- ^^^ meta.function-call support.function +-- ^ punctuation.separator.sequence +-- ^ constant.other.wildcard.asterisk +from test_by_example; + +COPY table1 (column1, column2, column3) FROM 'table1data.csv' +-- ^ keyword.other.dml +-- ^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +WITH HEADER=true; +-- ^ keyword.other +-- ^^^^^^ string.unquoted +-- ^ keyword.operator +-- ^^^^ constant.language.boolean.true +-- ^ punctuation.terminator.statement + +TRUNCATE table1; +-- ^^^^^ keyword.other.dml +-- ^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +SOURCE './myscript.cql'; +-- ^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.terminator.statement + +-- https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/cqlCreateIndex.html +CREATE TABLE myschema.users ( + userID uuid, + fname text, + lname text, + email text, + address text, + zip int, + state text, + PRIMARY KEY (userID) + ); + +CREATE INDEX user_state +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^^^^^^^^^ entity.name.struct.index.sql + ON myschema.users (state); +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE INDEX ON myschema.users (zip); +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^ meta.column-name +-- ^ punctuation.section.group.end + +CREATE INDEX todo_dates ON users (KEYS(todo)); +-- ^^^^^ meta.statement.create meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^ meta.function-call support.function.scalar +-- ^ punctuation.section.arguments.begin +-- ^^^^ meta.column-name +-- ^ punctuation.section.arguments.end +-- ^ punctuation.section.group.end + +CREATE INDEX entries_idx ON race (ENTRIES(race_wins)); +-- ^^^^ meta.statement.create meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.function-call support.function.scalar +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^ meta.column-name +-- ^ punctuation.section.arguments.end +-- ^ punctuation.section.group.end + +CREATE INDEX rnumbers_idx ON cycling.race_starts (FULL(rnumbers)); +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^ meta.function-call support.function.scalar +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.arguments.end +-- ^ punctuation.section.group.end + +SELECT album, tags +FROM playlists +WHERE tags CONTAINS 'blues'; +-- ^^^^^^^^ keyword.operator.logical + +SELECT * +FROM playlists +WHERE venue CONTAINS KEY '2014-09-22 22:00:00-0700'; +-- ^^^^^^^^^^^^ keyword.operator.logical + +SELECT * +FROM cycling.birthday_list +WHERE blist['age'] = '23'; +-- ^^^^^ meta.column-name +-- ^^^^^^^ meta.brackets.cql +-- ^ punctuation.section.brackets.begin +-- ^^^^^ string.quoted.single +-- ^ punctuation.section.brackets.end +-- ^ keyword.operator.comparison +-- ^^^^ string.quoted.single +-- ^ punctuation.terminator.statement + +SELECT * +FROM cycling.race_starts +WHERE rnumbers = [39,7,14]; +-- ^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^^^^ meta.brackets.cql +-- ^ punctuation.section.brackets.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement + +SELECT * +FROM ruling_stewards +WHERE (steward_name, king) = ('Boromir', 'Brego'); +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence +-- ^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end +-- ^ keyword.operator.comparison +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^ meta.group string.quoted.single +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^ meta.group string.quoted.single +-- ^ meta.group punctuation.section.group.end +-- ^ punctuation.terminator.statement + +SELECT WRITETIME (first_name) +--^^^^ keyword.other.dml +-- ^^^^^^^^^ meta.function-call support.function +FROM users +WHERE last_name = 'Jones'; + +INSERT INTO cycling.calendar (race_id, race_name, race_start_date, race_end_date) +VALUES (200, 'placeholder', '2015-05-27', '2015-05-27') +USING TTL; +-- ^^^^^^ keyword.other +-- ^ punctuation.terminator.statement + +UPDATE cycling.calendar +USING TTL 300 +-- ^^^^^^ keyword.other +-- ^^^ meta.number.integer.decimal constant.numeric.value +SET race_name = 'dummy' +-- <- keyword.other.dml +WHERE race_id = 200 + AND race_start_date = '2015-05-27' + AND race_end_date = '2015-05-27'; + +SELECT TTL(race_name) +-- ^^^ meta.function-call support.function +FROM cycling.calendar +WHERE race_id=200; + +-- https://docs.datastax.com/en/cql-oss/3.x/cql/cql_using/useQueryJSON.html +select json name, checkin_id, timestamp from checkin; +-- ^^^ keyword.other.dml +-- ^^^^ storage.modifier + +select name, checkin_id, toJson(timestamp) from checkin; +-- ^^^^^^ meta.function-call support.function + +update blah.table +--^^^^ keyword.other.dml +-- ^^^^^^^^^^ meta.table-name +set x = 4 +--^ keyword.other.dml +-- ^ meta.column-name +-- ^ keyword.operator +-- ^ meta.number.integer.decimal constant.numeric.value + +DROP USER iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ meta.username.sql + +DROP USER IF EXISTS iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ meta.username.sql diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql new file mode 100644 index 0000000000..bc1ff92d5d --- /dev/null +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -0,0 +1,4653 @@ +-- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" + +-- ---------------------------------------------------------------------------- +-- String Literals +-- https://mariadb.com/kb/en/string-literals +-- ---------------------------------------------------------------------------- + + '\0' -- ASCII NUL (0x00). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\'' -- Single quote (“'”). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\"' -- Double quote (“"”). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\b' -- Backspace. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\n' -- Newline, or linefeed,. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\r' -- Carriage return. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\t' -- Tab. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\Z' -- ASCII 26 (Control+Z). See note following the table. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\\' -- Backslash (“\”). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\%' -- “%” character. See note following the table. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\_' -- A “_” character. See note following the table. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + +-- ---------------------------------------------------------------------------- +-- Constants +-- https://mariadb.com/kb/en/reserved-words +-- ---------------------------------------------------------------------------- + + null none true false +-- ^ - constant +-- ^^^^ constant.language.null.sql +-- ^ - constant +-- ^^^^ constant.language.null.sql +-- ^ - constant +-- ^^^^ constant.language.boolean.true.sql +-- ^ - constant +-- ^^^^^ constant.language.boolean.false.sql +-- ^ - constant + + all default maxvalue +-- ^ - constant +-- ^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^^ constant.language.sql +-- ^ - constant + + inplace copy nocopy instant exclusive shared +-- ^ - constant +-- ^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^ constant.language.sql +-- ^ - constant + + system versioning +-- ^ - constant +-- ^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ - constant + +-- ---------------------------------------------------------------------------- +-- Data Types +-- https://mariadb.com/kb/en/data-types +-- ---------------------------------------------------------------------------- + + BIT BOOLEAN +-- ^ - storage +-- ^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage + + INT INT1 INT2 INT3 INT4 INT8 INTEGER FLOAT FLOAT4 FLOAT8 +-- ^ - storage +-- ^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage + + BIGINT MEDIUMINT SMALLINT TINYINT +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage + + DECIMAL DEC NUMBER NUMERIC FIXED +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^ storage.type.sql +-- ^ - storage + + DOUBLE PRECISION DOUBLE FLOAT REAL +-- ^ - storage +-- ^^^^^^^^^^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage + + CHAR BYTE +-- ^^^^^^^^^ storage.type.sql + + NATIONAL CHAR +-- ^^^^^^^^^^^^^ storage.type.sql + + ENUM('foo', 'bar') +-- ^^^^^^^^^^^^^^^^^^ - meta.function-call +-- ^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + + ENUM ('foo', 'bar') +-- ^^^^^^^^^^^^^^^^^^^ - meta.function-call +-- ^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + + INT(10) FIXED(10,2) TEXT(200) VARCHAR(10) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function-call +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.type.sql + + SET SET('foo', 'bar') +-- ^^^ keyword.other.dml.sql +-- ^^^ storage.type.sql +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + + UUID UUID() +-- ^^^^ storage.type.sql +-- ^^^^ meta.function-call.sql support.function.sql + + YEAR YEAR() +-- ^^^^ storage.type.sql +-- ^^^^ meta.function-call.sql support.function.sql + + SIGNED UNSIGNED ZEROFILL +-- ^^^^^^ storage.modifier.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^ storage.modifier.sql + +-- ---------------------------------------------------------------------------- +-- Units +-- https://mariadb.com/kb/en/reserved-words +-- ---------------------------------------------------------------------------- + + DAY_HOUR DAY_MICROSECOND DAY_MINUTE DAY_SECOND +-- ^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^ keyword.other.unit.sql + + HOUR_MICROSECOND HOUR_MINUTE HOUR_SECOND +-- ^^^^^^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^ keyword.other.unit.sql + + MINUTE_MICROSECOND MINUTE_SECOND +-- ^^^^^^^^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^^^ keyword.other.unit.sql + + SECOND_MICROSECOND +-- ^^^^^^^^^^^^^^^^^^ keyword.other.unit.sql + +-- ---------------------------------------------------------------------------- +-- Data Definition Statements +-- https://mariadb.com/kb/en/data-definition +-- ---------------------------------------------------------------------------- + +-- ---------------------------------------------------------------------------- +-- Create Database Statements +-- https://mariadb.com/kb/en/create-database +-- +-- CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name +-- [create_specification] ... +-- +-- create_specification: +-- [DEFAULT] CHARACTER SET [=] charset_name +-- | [DEFAULT] COLLATE [=] collation_name +-- | COMMENT [=] 'comment' +-- ---------------------------------------------------------------------------- + +CREATE DATABASE db_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ entity.name.struct.database.sql + +CREATE DATABASE IF NOT EXISTS db_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ entity.name.struct.database.sql + +CREATE OR REPLACE DATABASE db_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ entity.name.struct.database.sql + +CREATE SCHEMA schema_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ entity.name.struct.database.sql + +CREATE SCHEMA IF NOT EXISTS schema_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^ entity.name.struct.database.sql + +CREATE OR REPLACE SCHEMA schema_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ entity.name.struct.database.sql + + CHARACTER SET = 'utf-8' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^ meta.string.sql string.quoted.single.sql + + DEFAULT CHARACTER SET = 'utf-16' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql + DEFAULT CHARSET=utf8 +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql + COLLATE = 'collation' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + COMMENT = 'My new database' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + COMMENT 'My new database' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + +-- ---------------------------------------------------------------------------- +-- Create Event Statements +-- https://mariadb.com/kb/en/create-event +-- +-- CREATE [OR REPLACE] +-- [DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }] +-- EVENT +-- [IF NOT EXISTS] +-- event_name +-- ON SCHEDULE schedule +-- [ON COMPLETION [NOT] PRESERVE] +-- [ENABLE | DISABLE | DISABLE ON SLAVE] +-- [COMMENT 'comment'] +-- DO sql_statement; +-- +-- schedule: +-- AT timestamp [+ INTERVAL interval] ... +-- | EVERY interval +-- [STARTS timestamp [+ INTERVAL interval] ...] +-- [ENDS timestamp [+ INTERVAL interval] ...] +-- +-- interval: +-- quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE | +-- WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE | +-- DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND} +-- ---------------------------------------------------------------------------- + +CREATE EVENT event_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.event.sql + +CREATE DEFINER = user@host EVENT event_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.definer.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^ meta.username.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.event.sql + +CREATE EVENT IF NOT EXISTS event_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.event +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.event.sql + +CREATE EVENT event_name + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR + INTERVAL 3 MINUTE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^^ keyword.other.unit.sql + +CREATE EVENT event_name + ON SCHEDULE EVERY 1 MONTH +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql + + ON COMPLETION PRESERVE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ constant.language.sql + + ON COMPLETION NOT PRESERVE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + + ENABLE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql + + DISABLE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DISABLE ON SLAVE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql + + COMMENT 'my comment' +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + DO UPDATE myschema.mytable SET mycol = mycol + 1; +-- <- meta.statement.create.sql meta.event.sql +-- ^^^ meta.statement.create.sql meta.event.sql +-- ^ - meta.statement +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.arithmetic.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Create Function Statements +-- https://mariadb.com/kb/en/create-function +-- +-- CREATE [OR REPLACE] +-- [DEFINER = {user | CURRENT_USER | role | CURRENT_ROLE }] +-- [AGGREGATE] FUNCTION [IF NOT EXISTS] func_name ([func_parameter[,...]]) +-- RETURNS type +-- [characteristic ...] +-- RETURN func_body +-- +-- func_parameter: +-- [ IN | OUT | INOUT | IN OUT ] param_name type +-- +-- type: +-- Any valid MariaDB data type +-- +-- characteristic: +-- LANGUAGE SQL +-- | [NOT] DETERMINISTIC +-- | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } +-- | SQL SECURITY { DEFINER | INVOKER } +-- | COMMENT 'string' +-- +-- func_body: +-- Valid SQL procedure statement +-- +-- CREATE [OR REPLACE] [AGGREGATE] FUNCTION [IF NOT EXISTS] function_name +-- RETURNS {STRING|INTEGER|REAL|DECIMAL} +-- SONAME shared_library_name +-- ---------------------------------------------------------------------------- + +CREATE DEFINER = CURRENT_ROLE AGGREGATE FUNCTION foo +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.definer.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.user.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.function.sql + +CREATE FUNCTION func_name(IN param_name number, IN OUT out varchar) RETURN +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.parameters.sql meta.group.sql +-- ^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ entity.name.function.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ storage.modifier.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^^^^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ storage.modifier.sql +-- ^^^ variable.parameter.sql +-- ^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^^ keyword.control.flow.return.sql +-- + +CREATE AGGREGATE FUNCTION +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql + + func_name() +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^^^^^^ meta.function.sql entity.name.function.sql +-- ^ meta.function.parameters.sql meta.group.sql punctuation.section.group.begin.sql +-- ^ meta.function.parameters.sql meta.group.sql punctuation.section.group.end.sql + + RETURNS varchar(200) +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^ meta.parens.sql +-- ^ punctuation.definition.parens.begin.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.definition.parens.end.sql + + LANGUAGE SQL +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^ constant.other.language.sql + + NOT DETERMINISTIC +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^ storage.modifier.sql + + CONTAINS SQL +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql + + NO SQL +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^ storage.modifier.sql + + READS SQL DATA +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ storage.modifier.sql + + MODIFIES SQL DATA +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^ storage.modifier.sql + + SQL SECURITY DEFINER +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ constant.language.user.sql + SQL SECURITY INVOKER +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ constant.language.user.sql + + COMMENT 'string' +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql + + RETURN +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^ - meta.statement - meta.function + +CREATE FUNCTION function_name RETURNS STRING SONAME 'ha_connect.so'; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ entity.name.function.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ support.type.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Create Procedure Statements +-- https://mariadb.com/kb/en/create-function +-- +-- CREATE +-- [OR REPLACE] +-- [DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }] +-- PROCEDURE sp_name ([proc_parameter[,...]]) +-- [characteristic ...] routine_body +-- +-- proc_parameter: +-- [ IN | OUT | INOUT ] param_name type +-- +-- type: +-- Any valid MariaDB data type +-- +-- characteristic: +-- LANGUAGE SQL +-- | [NOT] DETERMINISTIC +-- | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } +-- | SQL SECURITY { DEFINER | INVOKER } +-- | COMMENT 'string' +-- +-- routine_body: +-- Valid SQL procedure statement +-- ---------------------------------------------------------------------------- + +CREATE PROCEDURE +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^ meta.statement.create.sql meta.function.sql keyword.other.ddl.sql + +CREATE OR REPLACE PROCEDURE sp_name (param int, out args varchar(200)) SELECT foo FROM bar; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.parameters.sql meta.group.sql +-- ^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ meta.function.sql keyword.other.ddl.sql +-- ^^^^^^^ entity.name.function.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ variable.parameter.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^ storage.modifier.sql +-- ^^^^ variable.parameter.sql +-- ^^^^^^^ storage.type.sql - meta.parens +-- ^^^^^ storage.type.sql meta.parens.sql +-- ^ punctuation.definition.parens.begin.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.definition.parens.end.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^ meta.column-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^ meta.table-name.sql +-- ^ punctuation.terminator.statement.sql + +CREATE PROCEDURE + sp_name + NOT DETERMINISTIC +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^ storage.modifier.sql + SQL SECURITY INVOKER +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ constant.language.user.sql + COMMENT 'my procedure' +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +BEGIN + + DECLARE @var INT = 0; +-- ^^^^^^^ keyword.other.sql +-- ^^^^ variable.other.sql +-- ^^^ storage.type +-- ^ keyword.operator.assignment.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + + DECLARE r ROW (c1 INT, c2 VARCHAR(10)); +-- ^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql + + IF @var = TRUE THEN +-- ^^ keyword.control.conditional.sql +-- ^^^^ variable.other.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ constant.language.boolean.true.sql +-- ^^^^ keyword.control.conditional.sql + + ELSEIF @var = FALSE THEN +-- ^^^^^^ keyword.control.conditional.sql +-- ^^^^ variable.other.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^ constant.language.boolean.false.sql +-- ^^^^ keyword.control.conditional.sql + + ELSE +-- ^^^^ keyword.control.conditional.sql + + END IF +-- ^^^^^^ keyword.control.conditional.sql + + LOOP +-- ^^^^ keyword.control.loop.sql + + END LOOP +-- ^^^^^^^^ keyword.control.loop.sql + + REPEAT +-- ^^^^^^ keyword.control.loop.sql + + END REPEAT +-- ^^^^^^^^^^ keyword.control.loop.sql + + WHILE TRUE +-- ^^^^^ keyword.control.loop.sql +-- ^^^^ constant.language.boolean.true.sql + + END WHILE +-- ^^^^^^^^^ keyword.control.loop.sql + + CONTINUE +-- ^^^^^^^^ keyword.control.flow.continue.sql + + EXIT +-- ^^^^ keyword.control.flow.exit.sql + + RETURN +-- ^^^^^^ keyword.control.flow.return.sql + +END + +-- ---------------------------------------------------------------------------- +-- Create Index Statements +-- https://mariadb.com/kb/en/create-index +-- +-- CREATE [OR REPLACE] [UNIQUE|FULLTEXT|SPATIAL] INDEX +-- [IF NOT EXISTS] index_name +-- [index_type] +-- ON tbl_name (index_col_name,...) +-- [WAIT n | NOWAIT] +-- [index_option] +-- [algorithm_option | lock_option] ... +-- +-- index_col_name: +-- col_name [(length)] [ASC | DESC] +-- +-- index_type: +-- USING {BTREE | HASH | RTREE} +-- +-- index_option: +-- [ KEY_BLOCK_SIZE [=] value +-- | index_type +-- | WITH PARSER parser_name +-- | COMMENT 'string' +-- | CLUSTERING={YES| NO} ] +-- [ IGNORED | NOT IGNORED ] +-- +-- algorithm_option: +-- ALGORITHM [=] {DEFAULT|INPLACE|COPY|NOCOPY|INSTANT} +-- +-- lock_option: +-- LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE} +-- ---------------------------------------------------------------------------- + +CREATE INDEX ON fancy_table(mytime); +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.other +-- ^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^ meta.group.sql + +CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ meta.statement.create keyword.other +-- ^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end +-- ^^^^^ keyword.other.dml.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql + +create fulltext index if not exists `myindex` ON mytable; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^ entity.name.struct.index +-- ^^ keyword.other +-- ^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE INDEX index_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql + USING BTREE +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql + ON tbl_name (col1(100) ASC, col2 DESC) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.end.sql + NOWAIT +-- ^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^ keyword.other.ddl.sql + WAIT 1 DAY +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^ keyword.other.ddl.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql + COMMENT 'my comment' +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + WITH PARSER parser_name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.other-name.sql + CLUSTERING = YES +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^ keyword.operator.comparison.sql +-- ^^^ constant.language.boolean.sql + KEY_BLOCK_SIZE 20 +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql + NOT IGNORED +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ keyword.other.ddl.sql + ALGORITHM INPLACE +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ constant.language.sql + LOCK SHARED +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ constant.language.sql + + +-- ---------------------------------------------------------------------------- +-- Create Role Statements +-- https://mariadb.com/kb/en/create-role +-- +-- CREATE [OR REPLACE] ROLE [IF NOT EXISTS] role +-- [WITH ADMIN +-- {CURRENT_USER | CURRENT_ROLE | user | role}] +-- ---------------------------------------------------------------------------- + +CREATE ROLE role +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword - entity +-- ^^^^ entity.name.user.sql +-- ^ - entity + +CREATE ROLE IF NOT EXISTS role +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^ - keyword +-- ^^^ keyword.operator.logical.sql +-- ^ - keyword +-- ^^^^^^ keyword.operator.logical.sql +-- ^ - keyword - entity +-- ^^^^ entity.name.user.sql +-- ^ - entity + +CREATE OR REPLACE ROLE IF NOT EXISTS role +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^ entity.name.user.sql + +CREATE OR REPLACE ROLE with WITH ADMIN lorinda@localhost +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.accessor.at.sql + +CREATE ROLE role WITH ADMIN CURRENT_ROLE +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ support.function.user.sql + + +-- ---------------------------------------------------------------------------- +-- Create Table Statements +-- https://mariadb.com/kb/en/create-table +-- +-- CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name +-- (create_definition,...) [table_options ]... [partition_options] +-- CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name +-- [(create_definition,...)] [table_options ]... [partition_options] +-- select_statement +-- CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name +-- { LIKE old_table_name | (LIKE old_table_name) } +-- +-- create_definition: +-- { col_name column_definition | index_definition | period_definition | CHECK (expr) } +-- +-- column_definition: +-- data_type +-- [NOT NULL | NULL] [DEFAULT default_value | (expression)] +-- [ON UPDATE [NOW | CURRENT_TIMESTAMP] [(precision)]] +-- [AUTO_INCREMENT] [ZEROFILL] [UNIQUE [KEY] | [PRIMARY] KEY] +-- [INVISIBLE] [{WITH|WITHOUT} SYSTEM VERSIONING] +-- [COMMENT 'string'] [REF_SYSTEM_ID = value] +-- [reference_definition] +-- | data_type [GENERATED ALWAYS] +-- AS { { ROW {START|END} } | { (expression) [VIRTUAL | PERSISTENT | STORED] } } +-- [UNIQUE [KEY]] [COMMENT 'string'] +-- +-- constraint_definition: +-- CONSTRAINT [constraint_name] CHECK (expression) +-- +-- select_statement: +-- [IGNORE | REPLACE] [AS] SELECT ... (Some legal select statement) +-- +-- table_options: +-- table_option, [table_option ...] +-- +-- table_option: +-- [STORAGE] ENGINE [=] engine_name +-- | AUTO_INCREMENT [=] value +-- | AVG_ROW_LENGTH [=] value +-- | [DEFAULT] CHARACTER SET [=] charset_name +-- | CHECKSUM [=] {0 | 1} +-- | [DEFAULT] COLLATE [=] collation_name +-- | COMMENT [=] 'string' +-- | CONNECTION [=] 'connect_string' +-- | DATA DIRECTORY [=] 'absolute path to directory' +-- | DELAY_KEY_WRITE [=] {0 | 1} +-- | ENCRYPTED [=] {YES | NO} +-- | ENCRYPTION_KEY_ID [=] value +-- | IETF_QUOTES [=] {YES | NO} +-- | INDEX DIRECTORY [=] 'absolute path to directory' +-- | INSERT_METHOD [=] { NO | FIRST | LAST } +-- | KEY_BLOCK_SIZE [=] value +-- | MAX_ROWS [=] value +-- | MIN_ROWS [=] value +-- | PACK_KEYS [=] {0 | 1 | DEFAULT} +-- | PAGE_CHECKSUM [=] {0 | 1} +-- | PAGE_COMPRESSED [=] {0 | 1} +-- | PAGE_COMPRESSION_LEVEL [=] {0 .. 9} +-- | PASSWORD [=] 'string' +-- | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT|PAGE} +-- | SEQUENCE [=] {0|1} +-- | STATS_AUTO_RECALC [=] {DEFAULT|0|1} +-- | STATS_PERSISTENT [=] {DEFAULT|0|1} +-- | STATS_SAMPLE_PAGES [=] {DEFAULT|value} +-- | TABLESPACE tablespace_name +-- | TRANSACTIONAL [=] {0 | 1} +-- | UNION [=] (tbl_name[,tbl_name]...) +-- | WITH SYSTEM VERSIONING +-- +-- partition_options: +-- PARTITION BY +-- { [LINEAR] HASH(expr) +-- | [LINEAR] KEY(column_list) +-- | RANGE(expr) +-- | LIST(expr) +-- | SYSTEM_TIME [INTERVAL time_quantity time_unit] [LIMIT num] } +-- [PARTITIONS num] +-- [SUBPARTITION BY +-- { [LINEAR] HASH(expr) +-- | [LINEAR] KEY(column_list) } +-- [SUBPARTITIONS num] +-- ] +-- [(partition_definition [, partition_definition] ...)] +-- +-- partition_definition: +-- PARTITION partition_name +-- [VALUES {LESS THAN {(expr) | MAXVALUE} | IN (value_list)}] +-- [[STORAGE] ENGINE [=] engine_name] +-- [COMMENT [=] 'comment_text' ] +-- [DATA DIRECTORY [=] 'data_dir'] +-- [INDEX DIRECTORY [=] 'index_dir'] +-- [MAX_ROWS [=] max_number_of_rows] +-- [MIN_ROWS [=] min_number_of_rows] +-- [TABLESPACE [=] tablespace_name] +-- [NODEGROUP [=] node_group_id] +-- [(subpartition_definition [, subpartition_definition] ...)] +-- +-- subpartition_definition: +-- SUBPARTITION logical_name +-- [[STORAGE] ENGINE [=] engine_name] +-- [COMMENT [=] 'comment_text' ] +-- [DATA DIRECTORY [=] 'data_dir'] +-- [INDEX DIRECTORY [=] 'index_dir'] +-- [MAX_ROWS [=] max_number_of_rows] +-- [MIN_ROWS [=] min_number_of_rows] +-- [TABLESPACE [=] tablespace_name] +-- [NODEGROUP [=] node_group_id] +-- ---------------------------------------------------------------------------- + +CREATE TABLE foo +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^ keyword.other.ddl +-- ^ - keyword +-- ^^^^^ keyword.other.ddl +-- ^ - keyword +-- ^^^ entity.name.struct.table.sql + +;CREATE OR REPLACE TABLE foo (id INTEGER PRIMARY KEY); +-- <- punctuation.terminator.statement.sql + -- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^^ keyword.other.ddl +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.struct +-- ^ - entity.name +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table some_schema.test2( id serial ); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ entity.name.struct +-- ^ punctuation.accessor.dot +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^ support.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table some_schema . test2 ( id serial ); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^ - entity.name +-- ^^^^^^^^^^^^^^^^^^^ entity.name.struct +-- ^ - entity.name +-- ^ punctuation.accessor.dot +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^ support.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create temporary table "testing123" (id integer); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ entity.name.struct.table.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table if not exists `dbo`."testing123" (id integer); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^ entity.name.struct.table.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.accessor.dot.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table IF NOT EXISTS `testing123` ( +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^ entity.name.struct.table.sql +-- ^ punctuation.section.group.begin.sql + + -- ------------------ + -- column definitions + -- ------------------ + + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^^ meta.column-name.sql +-- ^^^ storage.type.sql - meta.parens +-- ^^^^ storage.type.sql meta.parens.sql +-- ^ punctuation.definition.parens.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.definition.parens.end.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql + `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +-- ^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^^^^^^ storage.modifier.sql + `col` bool DEFAULT FALSE, +-- ^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier.sql +-- ^^^^^ constant.language.boolean.false.sql +-- ^ punctuation.separator.sequence + `fkey` INT UNSIGNED NULL REFERENCES test2(id), +-- ^^^^^^^^^^ storage.modifier.sql + `version` tinytext DEFAULT NULL COMMENT 'important clarification', +-- ^^^^^^^^ storage.type.sql + `percentage` float DEFAULT '0', + + `set` SET ('value1', 'value2') NOT NULL, +-- ^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^ punctuation.separator.sequence.sql + + -- ------------------ + -- index definitions + -- ------------------ + + UNIQUE KEY `testing123_search` (`col`, `version`), +-- ^^^^^^^^^^ storage.modifier.sql + KEY `testing123_col` (`col`), +-- ^^^ storage.modifier.sql + FULLTEXT KEY `testing123_version` (`version`) + +) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARACTER SET=utf8; + +create table fancy_table ( + id SERIAL, +-- ^^^^^^ support.type.sql + foreign_id integer, +-- ^^^^^^^ storage.type.sql + myflag boolean DEFAULT false, +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier.sql +-- ^^^^^ constant.language.boolean.false.sql + mycount double precision DEFAULT 1, +-- ^^^^^^^^^^^^^^^^^ storage.type.sql + fancy_column character varying(42) DEFAULT 'nice'::character varying, +-- ^^^^^^^^^^^^^^^^^^^^^^ storage.type.sql + mytime timestamp(3) without time zone DEFAULT now(), +-- ^^^^^^^^^^^^ storage.type.sql +-- ^ constant.numeric +-- ^^^^^^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ storage.modifier +-- ^^^ meta.function-call support.function +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end +-- ^ punctuation.separator.sequence + mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- TODO: seems like :: is a postgresql cast operator +-- ^^^^^^^^^^^^^^^^^^^ storage.modifier.sql + some_number numeric(5, 2) DEFAULT 0, +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.separator.sequence +-- ^ constant.numeric +-- ^^^^^^^ storage.modifier +-- ^ meta.number.integer.decimal constant.numeric.value + primary key (id), +-- ^^^^^^^^^^^ storage.modifier.sql + UNIQUE (foreign_id), + CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^ meta.group meta.group +-- ^^ meta.column-name +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^ meta.column-name +); + +CREATE TABLE foo LIKE bar; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.struct.table.sql +-- ^^^^ keyword.other.sql +-- ^^^ meta.table-name.sql +-- ^ punctuation.terminator.statement.sql + + +CREATE TABLE foo (col1, col2) + ENGINE = engine_name, +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + STORAGE ENGINE = engine_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + AUTO_INCREMENT = 30, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + AVG_ROW_LENGTH = 30, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + DEFAULT CHARACTER SET = 'utf-8', +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.sql + CHARACTER SET = 'utf-16', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + CHECKSUM = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + COLLATE = collation_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^ variable.parameter.sql + DEFAULT COLLATE = collation_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + COMMENT = 'string', +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^ variable.parameter.sql + CONNECTION = 'connect_string', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ variable.parameter.sql + DATA DIRECTORY = 'absolute path to directory', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + DELAY_KEY_WRITE = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + ENCRYPTED = NO, -- {YES | NO} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^ variable.parameter.sql + ENCRYPTION_KEY_ID = 30, +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^ variable.parameter.sql + IETF_QUOTES = YES, -- {YES | NO} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^ variable.parameter.sql + INDEX DIRECTORY = 'absolute path to directory', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + INSERT_METHOD = FIRST, -- { NO | FIRST | LAST } +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + KEY_BLOCK_SIZE = 30, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + MAX_ROWS = 30, +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + MIN_ROWS = 30, +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + PACK_KEYS = 1, -- {0 | 1 | DEFAULT} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^ variable.parameter.sql + PAGE_CHECKSUM = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + PAGE_COMPRESSED = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + PAGE_COMPRESSION_LEVEL = 9, -- {0 .. 9} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.sql + PASSWORD = 'string', +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + ROW_FORMAT = DYNAMIC, -- {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT|PAGE} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^ constant.language.sql + SEQUENCE = 0, -- {0|1} +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + STATS_AUTO_RECALC = DEFAULT, -- {DEFAULT|0|1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^ variable.parameter.sql + STATS_PERSISTENT = DEFAULT, -- {DEFAULT|0|1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^ variable.parameter.sql + STATS_SAMPLE_PAGES = DEFAULT, -- {DEFAULT|value} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^ variable.parameter.sql + TABLESPACE tablespace_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^^^^ meta.other-name.sql + TRANSACTIONAL = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + UNION = (`table1`, "table2", table3), -- (tbl_name[,tbl_name]...) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^ variable.parameter.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.tables.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.table-name.sql +-- ^ punctuation.section.sequence.end.sql + WITH SYSTEM VERSIONING +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^ keyword.other.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql +; +-- <- punctuation.terminator.statement.sql + +CREATE + TABLE +-- ^^^^^ meta.statement.create.sql meta.table.sql keyword.other.ddl.sql + foo +-- ^^^ meta.statement.create.sql meta.table.sql entity.name.struct.table.sql + (col1, col2) +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql + PARTITION BY +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql keyword.other.sql + LINEAR HASH( 20 + YEAR(col2) ) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^ storage.modifier.sql +-- ^^^^ support.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^^^ meta.function-call +-- ^^^^ support.function.sql +-- ^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.arguments.end.sql +-- ^ punctuation.section.group.end.sql + LINEAR KEY(col1, col2) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^ storage.modifier.sql +-- ^^^ support.function.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + RANGE(10) +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^ support.function.sql +-- ^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql + LIST() +-- ^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^ support.function.sql +-- ^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.end.sql + SYSTEM_TIME INTERVAL 10 DAY LIMIT 10 +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql +-- ^^^^^ keyword.other.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql + + PARTITIONS 3 +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ keyword.other.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + SUBPARTITION BY +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ keyword.other.sql + LINEAR HASH(10 + 20) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql + + LINEAR KEY(col1, col2) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql + SUBPARTITIONS 3 +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql + + ( +-- ^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql + PARTITION partition1 +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.partition.sql + VALUES LESS THAN MAXVALUE +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + VALUES LESS THAN (20) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.operator.logical.sql +-- ^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql + ENGINE = engine_name +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + COMMENT = 'comment_text' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + DATA DIRECTORY = 'data_dir' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql + INDEX DIRECTORY = 'index_dir' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + MAX_ROWS = 20 +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql + MIN_ROWS = 4 +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + TABLESPACE = tablespace_name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^ meta.other-name.sql + NODEGROUP = 32 + + ( +-- ^ meta.group.partitions.sql - meta.sequence meta.sequence +-- ^^ meta.group.partitions.sql meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql + subpartition parition1 +-- ^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ entity.name.struct.partition.sql + ENGINE engine_name +-- ^^^^^^ variable.parameter.sql + COMMENT 'comment_text' +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^^^ string.quoted.single.sql + + , subpartition parition2 +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ entity.name.struct.partition.sql + ), +-- ^^ meta.group.partitions.sql meta.group.partitions.sql +-- ^ meta.group.partitions.sql - meta.sequence meta.sequence +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.separator.sequence.sql + + PARTITION partition2 +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.partition.sql + VALUES IN ("value1", "value2", "value3") +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.string.sql string.quoted.double.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.string.sql string.quoted.double.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.string.sql string.quoted.double.sql +-- ^ punctuation.section.group.end.sql +-- + STORAGE ENGINE = engine_name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + ) +-- ^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^ punctuation.section.group.end.sql + + +-- ---------------------------------------------------------------------------- +-- Create User Statements +-- https://mariadb.com/kb/en/create-user +-- +-- CREATE [OR REPLACE] USER [IF NOT EXISTS] +-- user_specification [,user_specification ...] +-- [REQUIRE {NONE | tls_option [[AND] tls_option ...] }] +-- [WITH resource_option [resource_option ...] ] +-- [lock_option] [password_option] +-- +-- user_specification: +-- username [authentication_option] +-- +-- authentication_option: +-- IDENTIFIED BY 'password' +-- | IDENTIFIED BY PASSWORD 'password_hash' +-- | IDENTIFIED {VIA|WITH} authentication_rule [OR authentication_rule ...] +-- +-- authentication_rule: +-- authentication_plugin +-- | authentication_plugin {USING|AS} 'authentication_string' +-- | authentication_plugin {USING|AS} PASSWORD('password') +-- +-- tls_option: +-- SSL +-- | X509 +-- | CIPHER 'cipher' +-- | ISSUER 'issuer' +-- | SUBJECT 'subject' +-- +-- resource_option: +-- MAX_QUERIES_PER_HOUR count +-- | MAX_UPDATES_PER_HOUR count +-- | MAX_CONNECTIONS_PER_HOUR count +-- | MAX_USER_CONNECTIONS count +-- | MAX_STATEMENT_TIME time +-- +-- password_option: +-- PASSWORD EXPIRE +-- | PASSWORD EXPIRE DEFAULT +-- | PASSWORD EXPIRE NEVER +-- | PASSWORD EXPIRE INTERVAL N DAY +-- +-- lock_option: +-- ACCOUNT LOCK +-- | ACCOUNT UNLOCK +-- ---------------------------------------------------------------------------- + +CREATE USER IF NOT EXISTS +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql + user1, +-- <- meta.statement.create.sql +-- ^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^ entity.name.user.sql +-- ^ punctuation.separator.sequence.sql + + user2@localhost IDENTIFIED BY 'password', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^ entity.name.user.sql +-- ^ punctuation.accessor.at.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + 'user3@'@'%' IDENTIFIED BY PASSWORD 'password_hash', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ entity.name.user.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ - punctuation +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ constant.other.wildcard.percent.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user4 IDENTIFIED VIA +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^ entity.name.user.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql + + auth_plugin1, +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin2 AS 'auth_string', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin3 USING 'auth_string', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin4 AS PASSWORD('password') +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call.sql +-- ^^^^^^^^ support.function.sql +-- ^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + + REQUIRE NONE +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.null.sql + + REQUIRE SSL AND CIPHER 'ciphername' X509 AND SUBJECT 'subject' +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ constant.language.sql +-- ^^^^^^^^^ meta.string.sql string.quoted.single.sql + + WITH MAX_QUERIES_PER_HOUR 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_UPDATES_PER_HOUR 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_CONNECTIONS_PER_HOUR 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_USER_CONNECTIONS 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_STATEMENT_TIME 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + ACCOUNT LOCK +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.sql + + ACCOUNT UNLOCK +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ constant.language.sql + + PASSWORD EXPIRE DEFAULT +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ constant.language.sql + + PASSWORD EXPIRE NEVER +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql + + PASSWORD EXPIRE INTERVAL 5 DAY +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql + + +-- ---------------------------------------------------------------------------- +-- Alter Database Statements +-- https://mariadb.com/kb/en/alter-database +-- +-- ALTER {DATABASE | SCHEMA} [db_name] +-- alter_specification ... +-- ALTER {DATABASE | SCHEMA} db_name +-- UPGRADE DATA DIRECTORY NAME +-- +-- alter_specification: +-- [DEFAULT] CHARACTER SET [=] charset_name +-- | [DEFAULT] COLLATE [=] collation_name +-- | COMMENT [=] 'comment' +-- ---------------------------------------------------------------------------- + +ALTER DATABASE db_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.database-name.sql + + +ALTER DATABASE db_name UPGRADE DATA DIRECTORY NA +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^ - meta.statement.alter +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.database-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ - keyword + +ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAME +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.database-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^^^^^^^^^^ keyword.other.ddl.sql + +ALTER SCHEMA schema_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.database-name.sql + + CHARACTER SET = 'utf-8' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^ meta.string.sql string.quoted.single.sql + + DEFAULT CHARACTER SET = 'utf-16' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql + + COLLATE = 'collation' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + COMMENT = 'My new database' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + +-- ---------------------------------------------------------------------------- +-- Alter Event Statements +-- https://mariadb.com/kb/en/alter-event +-- +-- ALTER +-- [DEFINER = { user | CURRENT_USER }] +-- EVENT event_name +-- [ON SCHEDULE schedule] +-- [ON COMPLETION [NOT] PRESERVE] +-- [RENAME TO new_event_name] +-- [ENABLE | DISABLE | DISABLE ON SLAVE] +-- [COMMENT 'comment'] +-- [DO sql_statement] +-- ---------------------------------------------------------------------------- + +ALTER EVENT event_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.event-name.sql + +ALTER DEFINER = user@host EVENT event_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.definer.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^ meta.username.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.event-name.sql + +ALTER EVENT IF NOT EXISTS event_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql - meta.event +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.event-name.sql + +ALTER EVENT event_name + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR + INTERVAL 3 MINUTE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^^ keyword.other.unit.sql + +ALTER EVENT event_name + ON SCHEDULE EVERY 1 MONTH +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql + + ON COMPLETION PRESERVE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ constant.language.sql + + ON COMPLETION NOT PRESERVE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + + ENABLE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql + + DISABLE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DISABLE ON SLAVE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql + + COMMENT 'my comment' +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + DO UPDATE myschema.mytable SET mycol = mycol + 1; +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^ meta.statement.alter.sql meta.event.sql +-- ^ - meta.statement +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.arithmetic.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Alter Table Statements +-- https://mariadb.com/kb/en/alter-table +-- +-- ALTER [ONLINE] [IGNORE] TABLE [IF EXISTS] tbl_name +-- [WAIT n | NOWAIT] +-- alter_specification [, alter_specification] ... +-- +-- alter_specification: +-- table_option ... +-- | ADD [COLUMN] [IF NOT EXISTS] col_name column_definition +-- [FIRST | AFTER col_name ] +-- | ADD [COLUMN] [IF NOT EXISTS] (col_name column_definition,...) +-- | ADD {INDEX|KEY} [IF NOT EXISTS] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- | ADD [CONSTRAINT [symbol]] PRIMARY KEY +-- [index_type] (index_col_name,...) [index_option] ... +-- | ADD [CONSTRAINT [symbol]] +-- UNIQUE [INDEX|KEY] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- | ADD FULLTEXT [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- | ADD SPATIAL [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- | ADD [CONSTRAINT [symbol]] +-- FOREIGN KEY [IF NOT EXISTS] [index_name] (index_col_name,...) +-- reference_definition +-- | ADD PERIOD FOR SYSTEM_TIME (start_column_name, end_column_name) +-- | ALTER [COLUMN] col_name SET DEFAULT literal | (expression) +-- | ALTER [COLUMN] col_name DROP DEFAULT +-- | ALTER {INDEX|KEY} index_name [NOT] INVISIBLE +-- | CHANGE [COLUMN] [IF EXISTS] old_col_name new_col_name column_definition +-- [FIRST | AFTER col_name] +-- | MODIFY [COLUMN] [IF EXISTS] col_name column_definition +-- [FIRST | AFTER col_name] +-- | DROP [COLUMN] [IF EXISTS] col_name [RESTRICT|CASCADE] +-- | DROP PRIMARY KEY +-- | DROP {INDEX|KEY} [IF EXISTS] index_name +-- | DROP FOREIGN KEY [IF EXISTS] index_name +-- | DROP CONSTRAINT [IF EXISTS] constraint_name +-- | DISABLE KEYS +-- | ENABLE KEYS +-- | RENAME [TO] new_tbl_name +-- | ORDER BY col_name [, col_name] ... +-- | RENAME COLUMN old_col_name TO new_col_name +-- | RENAME {INDEX|KEY} old_index_name TO new_index_name +-- | CONVERT TO CHARACTER SET charset_name [COLLATE collation_name] +-- | [DEFAULT] CHARACTER SET [=] charset_name +-- | [DEFAULT] COLLATE [=] collation_name +-- | DISCARD TABLESPACE +-- | IMPORT TABLESPACE +-- | ALGORITHM [=] {DEFAULT|INPLACE|COPY|NOCOPY|INSTANT} +-- | LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE} +-- | FORCE +-- | partition_options +-- | CONVERT TABLE normal_table TO partition_definition +-- | CONVERT PARTITION partition_name TO TABLE tbl_name +-- | ADD PARTITION [IF NOT EXISTS] (partition_definition) +-- | DROP PARTITION [IF EXISTS] partition_names +-- | COALESCE PARTITION number +-- | REORGANIZE PARTITION [partition_names INTO (partition_definitions)] +-- | ANALYZE PARTITION partition_names +-- | CHECK PARTITION partition_names +-- | OPTIMIZE PARTITION partition_names +-- | REBUILD PARTITION partition_names +-- | REPAIR PARTITION partition_names +-- | EXCHANGE PARTITION partition_name WITH TABLE tbl_name +-- | REMOVE PARTITIONING +-- | ADD SYSTEM VERSIONING +-- | DROP SYSTEM VERSIONING +-- +-- index_col_name: +-- col_name [(length)] [ASC | DESC] +-- +-- index_type: +-- USING {BTREE | HASH | RTREE} +-- +-- index_option: +-- [ KEY_BLOCK_SIZE [=] value +-- | index_type +-- | WITH PARSER parser_name +-- | COMMENT 'string' +-- | CLUSTERING={YES| NO} ] +-- [ IGNORED | NOT IGNORED ] +-- +-- table_options: +-- table_option [[,] table_option] ... +-- ---------------------------------------------------------------------------- + +ALTER ONLINE IGNORE TABLE IF EXISTS tbl_name WAIT 100 +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- ^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql + + ADD id INTEGER PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql + + ADD COLUMN id INTEGER PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql + + ADD COLUMN IF NOT EXISTS id INTEGER PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql + + ADD (id INTEGER PRIMARY KEY, ) +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.end.sql + + ADD COLUMN (id INTEGER PRIMARY KEY, ) FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ keyword.other.position.sql + + ADD COLUMN IF NOT EXISTS (id INTEGER PRIMARY KEY, ) AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + +-- ---------------------------------------------------------------------------- +-- ADD {INDEX|KEY} [IF NOT EXISTS] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- ADD FULLTEXT [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- ADD SPATIAL [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD INDEX IF NOT EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD FULLTEXT INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD SPATIAL INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD FULLTEXT KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD SPATIAL KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD KEY IF NOT EXISTS index_name, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD INDEX index_name USING BTREE (col1, col2, col3), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + + ADD INDEX index_name (col1, col2, col3) USING BTREE KEY_BLOCK_SIZE 10 WITH PARSER parser CLUSTERING = NO NOT IGNORED +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^ keyword.operator.comparison.sql +-- ^^ constant.language.boolean.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ keyword.other.ddl.sql + +-- ---------------------------------------------------------------------------- +-- ADD [CONSTRAINT [symbol]] +-- FOREIGN KEY [IF NOT EXISTS] [index_name] (index_col_name,...) +-- reference_definition +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD FOREIGN KEY (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD FOREIGN KEY IF NOT EXISTS (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD FOREIGN KEY index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD FOREIGN KEY IF NOT EXISTS index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD CONSTRAINT FOREIGN KEY index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD CONSTRAINT symbol FOREIGN KEY index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + +-- ---------------------------------------------------------------------------- +-- ADD [CONSTRAINT [symbol]] PRIMARY KEY +-- [index_type] (index_col_name,...) [index_option] ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD PRIMARY KEY (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql +-- ^ punctuation.separator.sequence.sql + + ADD CONSTRAINT PRIMARY KEY (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT symbol PRIMARY KEY (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT symbol PRIMARY KEY USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + +-- ---------------------------------------------------------------------------- +-- ADD [CONSTRAINT [symbol]] +-- UNIQUE [INDEX|KEY] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD UNIQUE INDEX index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD UNIQUE KEY index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT UNIQUE KEY index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT symbol UNIQUE KEY index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + +-- ---------------------------------------------------------------------------- +-- ADD PARTITION ... +-- ADD PERIOD ... +-- ADD SYSTEM VERSIONING +-- ---------------------------------------------------------------------------- + + ADD PARTITION ( +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- + partition1 +-- ^^^^^^^^^^ entity.name.struct.partition.sql + VALUES LESS THAN MAXVALUE +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + ), + + ADD PARTITION IF NOT EXISTS (partition1 DATA DIRECTORY '../dir'), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.end.sql + + ADD PERIOD FOR SYSTEM_TIME (start_column_name, end_column_name), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + + ADD SYSTEM VERSIONING +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql + +-- ---------------------------------------------------------------------------- +-- CHANGE [COLUMN] [IF EXISTS] old_col_name new_col_name column_definition +-- [FIRST | AFTER col_name] +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + CHANGE old_col new_col INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + CHANGE IF EXISTS old_col new_col INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + + CHANGE COLUMN old_col new_col INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + CHANGE COLUMN IF EXISTS old_col new_col INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + + CHANGE COLUMN old_col new_col ENUM('foo', 'bar') +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^ storage.type.sql - meta.parens +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + +-- ---------------------------------------------------------------------------- +-- MODIFY [COLUMN] [IF EXISTS] col_name column_definition +-- [FIRST | AFTER col_name] +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + MODIFY col_name INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + MODIFY IF EXISTS col_name INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + + MODIFY COLUMN col_name INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + MODIFY COLUMN IF EXISTS col_name INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + +-- ---------------------------------------------------------------------------- +-- DROP [COLUMN] [IF EXISTS] col_name [RESTRICT|CASCADE] +-- DROP PRIMARY KEY +-- DROP {INDEX|KEY} [IF EXISTS] index_name +-- DROP FOREIGN KEY [IF EXISTS] fk_symbol +-- DROP CONSTRAINT [IF EXISTS] constraint_name +-- DROP PARTITION [IF EXISTS] partition_names +-- DROP SYSTEM VERSIONING +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + DROP col_name RESTRICT +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^^ keyword.other.ddl.sql + + DROP IF EXISTS col_name RESTRICT +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^^ keyword.other.ddl.sql + + DROP COLUMN col_name CASCADE +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DROP COLUMN IF EXISTS col_name CASCADE +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DROP CONSTRAINT constraint_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.constraint-name.sql + + DROP CONSTRAINT IF EXISTS constraint_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^ meta.constraint-name.sql + + DROP INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP INDEX IF EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP KEY IF EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP FOREIGN KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP FOREIGN KEY IF EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql + + DROP PARTITION partition_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.partition-name.sql + + DROP PARTITION IF EXISTS partition_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^ meta.partition-name.sql + + DROP SYSTEM VERSIONING +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql + +-- ---------------------------------------------------------------------------- +-- RENAME ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + RENAME new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.table-name.sql + + RENAME TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.table-name.sql + + RENAME COLUMN name TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^ meta.column-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql + + RENAME INDEX name TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^ meta.index-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.index-name.sql + + RENAME KEY name TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ meta.index-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.index-name.sql + +ALTER TABLE tbl_name ALGORITHM = INPLACE +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql + +-- ---------------------------------------------------------------------------- +-- Alter User Statements +-- https://mariadb.com/kb/en/alter-user +-- +-- ALTER USER [IF EXISTS] +-- user_specification [,user_specification] ... +-- [REQUIRE {NONE | tls_option [[AND] tls_option] ...}] +-- [WITH resource_option [resource_option] ...] +-- [lock_option] [password_option] +-- +-- user_specification: +-- username [authentication_option] +-- +-- authentication_option: +-- IDENTIFIED BY 'password' +-- | IDENTIFIED BY PASSWORD 'password_hash' +-- | IDENTIFIED {VIA|WITH} authentication_rule [OR authentication_rule] ... +-- +-- authentication_rule: +-- authentication_plugin +-- | authentication_plugin {USING|AS} 'authentication_string' +-- | authentication_plugin {USING|AS} PASSWORD('password') +-- +-- tls_option +-- SSL +-- | X509 +-- | CIPHER 'cipher' +-- | ISSUER 'issuer' +-- | SUBJECT 'subject' +-- +-- resource_option +-- MAX_QUERIES_PER_HOUR count +-- | MAX_UPDATES_PER_HOUR count +-- | MAX_CONNECTIONS_PER_HOUR count +-- | MAX_USER_CONNECTIONS count +-- | MAX_STATEMENT_TIME time +-- +-- password_option: +-- PASSWORD EXPIRE +-- | PASSWORD EXPIRE DEFAULT +-- | PASSWORD EXPIRE NEVER +-- | PASSWORD EXPIRE INTERVAL N DAY +-- +-- lock_option: +-- ACCOUNT LOCK +-- | ACCOUNT UNLOCK +-- ---------------------------------------------------------------------------- + +ALTER USER IF EXISTS +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql + user1, +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql + + user2 IDENTIFIED BY 'password', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user3 IDENTIFIED BY PASSWORD 'password_hash', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user4 IDENTIFIED VIA +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql + + auth_plugin1, +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin2 AS 'auth_string', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin3 USING 'auth_string', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin4 AS PASSWORD('password') +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call.sql +-- ^^^^^^^^ support.function.sql +-- ^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + + REQUIRE NONE +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.null.sql + + REQUIRE SSL AND CIPHER 'ciphername' X509 AND SUBJECT 'subject' +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ constant.language.sql +-- ^^^^^^^^^ meta.string.sql string.quoted.single.sql + + WITH MAX_QUERIES_PER_HOUR 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_UPDATES_PER_HOUR 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_CONNECTIONS_PER_HOUR 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_USER_CONNECTIONS 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_STATEMENT_TIME 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + ACCOUNT LOCK +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.sql + + ACCOUNT UNLOCK +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ constant.language.sql + + PASSWORD EXPIRE DEFAULT +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ constant.language.sql + + PASSWORD EXPIRE NEVER +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql + + PASSWORD EXPIRE INTERVAL 5 DAY +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql + + +-- ---------------------------------------------------------------------------- +-- Drop Statements +-- https://mariadb.com/kb/en/drop +-- ---------------------------------------------------------------------------- + +DROP +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword + + +-- ---------------------------------------------------------------------------- +-- Drop Database Statements +-- https://mariadb.com/kb/en/drop-database +-- +-- DROP {DATABASE | SCHEMA} [IF EXISTS] db_name +-- ---------------------------------------------------------------------------- + +DROP DATABASE db_name ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.database.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^ meta.database-name.sql +-- ^ punctuation.terminator.statement.sql + +DROP DATABASE IF EXISTS db_name ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.database.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.database-name.sql +-- ^ punctuation.terminator.statement.sql + +DROP SCHEMA schema_name ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^^ meta.database.sql meta.database-name.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Drop Event Statements +-- https://mariadb.com/kb/en/drop-event +-- +-- DROP EVENT [IF EXISTS] event_name +-- ---------------------------------------------------------------------------- + +DROP EVENT event ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^ meta.statement.drop.sql meta.event.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword - meta.event-name +-- ^^^^^ meta.event-name.sql +-- ^ - meta.event-name +-- ^ punctuation.terminator.statement.sql + +DROP EVENT IF EXISTS event ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.event.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^ - keyword +-- ^^^^^^ keyword.operator.logical.sql +-- ^ - keyword - meta.event-name +-- ^^^^^ meta.event-name.sql +-- ^ - meta.event-name +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Drop Index Statements +-- https://mariadb.com/kb/en/drop-index +-- +-- DROP INDEX [IF EXISTS] index_name ON tbl_name +-- [WAIT n |NOWAIT] +-- ---------------------------------------------------------------------------- + +DROP INDEX index_name ON tbl_name NOWAIT; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.index.sql +-- ^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^ keyword.other.ddl.sql + +-- ---------------------------------------------------------------------------- +-- Drop Role Statements +-- https://mariadb.com/kb/en/drop-role +-- +-- DROP ROLE [IF EXISTS] role_name [,role_name ...] +-- ---------------------------------------------------------------------------- + +DROP ROLE role ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +DROP ROLE IF EXISTS role1, role2, role3; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^ - keyword +-- ^^^^^^ keyword.operator.logical.sql +-- ^ - keyword +-- ^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Drop User Statements +-- https://mariadb.com/kb/en/drop-user +-- +-- DROP USER [IF EXISTS] user_name [, user_name] ... +-- ---------------------------------------------------------------------------- + +DROP USER bob@'%' ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.username.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.terminator.statement.sql + +DROP USER iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^^^^ meta.username.sql + +DROP USER IF EXISTS ify, clara@localhost ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Grant Statements +-- https://mariadb.com/kb/en/grant +-- +-- GRANT +-- priv_type [(column_list)] +-- [, priv_type [(column_list)]] ... +-- ON [object_type] priv_level +-- TO user_specification [ user_options ...] +-- +-- user_specification: +-- username [authentication_option] +-- +-- authentication_option: +-- IDENTIFIED BY 'password' +-- | IDENTIFIED BY PASSWORD 'password_hash' +-- | IDENTIFIED {VIA|WITH} authentication_rule [OR authentication_rule ...] +-- +-- authentication_rule: +-- authentication_plugin +-- | authentication_plugin {USING|AS} 'authentication_string' +-- | authentication_plugin {USING|AS} PASSWORD('password') +-- +-- GRANT PROXY ON username +-- TO user_specification [, user_specification ...] +-- [WITH GRANT OPTION] +-- +-- GRANT rolename TO grantee [, grantee ...] +-- [WITH ADMIN OPTION] +-- +-- grantee: +-- rolename +-- username [authentication_option] +-- +-- user_options: +-- [REQUIRE {NONE | tls_option [[AND] tls_option] ...}] +-- [WITH with_option [with_option] ...] +-- +-- object_type: +-- TABLE +-- | FUNCTION +-- | PROCEDURE +-- | PACKAGE +-- +-- priv_level: +-- * +-- | *.* +-- | db_name.* +-- | db_name.tbl_name +-- | tbl_name +-- | db_name.routine_name +-- +-- with_option: +-- GRANT OPTION +-- | resource_option +-- +-- resource_option: +-- MAX_QUERIES_PER_HOUR count +-- | MAX_UPDATES_PER_HOUR count +-- | MAX_CONNECTIONS_PER_HOUR count +-- | MAX_USER_CONNECTIONS count +-- | MAX_STATEMENT_TIME time +-- +-- tls_option: +-- SSL +-- | X509 +-- | CIPHER 'cipher' +-- | ISSUER 'issuer' +-- | SUBJECT 'subject' +-- ---------------------------------------------------------------------------- + +GRANT +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^ meta.statement.grant.sql keyword.other.authorization.sql +-- ^ meta.statement.grant.sql - keyword + +GRANT ALL +-- ^^ keyword.other.authorization.sql +-- ^^^ constant.language.sql + +GRANT ALL PRIVILEGES +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^ constant.language.sql + +GRANT DROP TABLE, ALTER COLUMN +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^ punctuation.separator.sequence.sql + +GRANT ALTER COLUMN ON * +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql + +GRANT ALTER TABLE ON *.* +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^^^ meta.other-name.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^ punctuation.accessor.dot.sql +-- ^ constant.other.wildcard.asterisk.sql + +GRANT ALTER INDEX ON db_name.* +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.accessor.dot.sql +-- ^ constant.other.wildcard.asterisk.sql + +GRANT ALTER COLUMN ON db_name.table_name +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.accessor.dot.sql + +GRANT ALTER COLUMN ON table_name +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^ meta.other-name.sql + +GRANT CREATE INDEX ON TABLE * TO user1@% IDENTIFIED BY 'password' ; +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^ keyword.context.sql +-- ^^^^^ storage.type.sql +-- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql +-- ^^ keyword.context.sql +-- ^^^^^^^ meta.username.sql +-- ^ punctuation.accessor.at.sql +-- ^ constant.other.wildcard.percent.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + +GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_hash' ; +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^ storage.type.sql +-- ^^^ meta.other-name.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + +GRANT CREATE INDEX ON PACKAGE *.* TO "user1" IDENTIFIED VIA auth1 or auth2 ; +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^ keyword.context.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ meta.other-name.sql +-- ^^ keyword.context.sql +-- ^^^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^ meta.other-name.sql +-- ^ punctuation.terminator.statement.sql + +GRANT PROXY +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^^^^ keyword.other.ddl.sql + ON username +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql + TO user1 IDENTIFIED BY 'password', +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + user2 IDENTIFIED VIA auth USING PASSWORD('passord') +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ meta.other-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.function-call.sql +-- ^^^^^^^^ support.function.sql +-- ^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + WITH GRANT OPTION ; +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^ punctuation.terminator.statement.sql + +GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^ meta.username.sql +-- ^^ keyword.context.sql +-- ^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.username.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Rename User Statements +-- https://mariadb.com/kb/en/rename-user +-- +-- RENAME USER old_user TO new_user +-- [, old_user TO new_user] ... +-- ---------------------------------------------------------------------------- + +RENAME +-- <- meta.statement.rename.sql keyword.other.authorization.sql +-- ^^^^ meta.statement.rename.sql +-- ^^^ keyword.other.authorization.sql +-- ^ - keyword + +RENAME USER +-- <- meta.statement.rename.sql keyword.other.authorization.sql +-- ^^^^^^^^^ meta.statement.rename.sql +-- ^^^ keyword.other.authorization.sql +-- ^ - keyword +-- ^^^^ keyword.other.authorization.sql +-- ^ - keyword + +RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; +-- <- meta.statement.rename.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.rename.sql +-- ^^^ keyword.other.authorization.sql +-- ^ - keyword +-- ^^^^ keyword.other.authorization.sql +-- ^ - keyword +-- ^^^^^^^^ meta.username.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.username.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Revoke Statements +-- https://mariadb.com/kb/en/revoke +-- +-- REVOKE +-- priv_type [(column_list)] +-- [, priv_type [(column_list)]] ... +-- ON [object_type] priv_level +-- FROM user [, user] ... +-- +-- REVOKE ALL PRIVILEGES, GRANT OPTION +-- FROM user [, user] ... +-- ---------------------------------------------------------------------------- + +REVOKE ; +-- <- meta.statement.revoke.sql keyword.other.authorization.sql +-- ^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.authorization.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE ALTER COLUMN (`col1`, `names`) ; +-- <- meta.statement.revoke.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE ALL PRIVILEGES, GRANT OPTION FROM user@'%', user2 ; +-- <- meta.statement.revoke.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^ constant.language.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE SUPER ON *.* FROM 'alexander'@'localhost'; +-- <- meta.statement.revoke.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.authorization.sql +-- ^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^ meta.other-name.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^ punctuation.accessor.dot.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.context.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE ADMIN OPTION FOR role FROM grantee, grantee2 ; +-- <- meta.statement.revoke.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^^ keyword.context.sql +-- ^^^^ meta.username.sql +-- ^^^^ keyword.context.sql +-- ^^^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE role1, role2 FROM grantee, grantee2 ; +-- <- meta.statement.revoke.sql keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^^ keyword.context.sql +-- ^^^^^^^ meta.username.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Set Password Statements +-- https://mariadb.com/kb/en/set-password +-- +-- SET PASSWORD [FOR user] = +-- { +-- PASSWORD('some password') +-- | OLD_PASSWORD('some password') +-- | 'encrypted password' +-- } +-- ---------------------------------------------------------------------------- + +SET +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^ meta.statement.set.sql - keyword + +SET PASSWORD = +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^ meta.statement.set.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^ keyword.operator.assignment.sql + +SET PASSWORD FOR user1@localhost = +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.accessor.at.sql +-- ^ keyword.operator.assignment.sql + +SET PASSWORD = PASSWORD('some password') +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^^ meta.function-call - meta.group +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql meta.group.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^ support.function.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + +SET PASSWORD = OLD_PASSWORD('some password'); +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^^^^^^ meta.function-call - meta.group +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql meta.group.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^ support.function.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql +-- ^ punctuation.terminator.statement.sql + +SET PASSWORD for `user@`@'%' = 'encrypted password'; +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ constant.other.wildcard.percent.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Set Role Statements +-- https://mariadb.com/kb/en/set-role +-- +-- SET ROLE { role | NONE } +-- ---------------------------------------------------------------------------- + +SET ROLE NONE +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^ meta.statement.set.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.null.sql + +SET ROLE role +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^ meta.statement.set.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ meta.username.sql + +SET DEFAULT ROLE NONE +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.null.sql + +SET DEFAULT ROLE role +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ meta.username.sql + +SET DEFAULT ROLE NONE FOR user@host +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.null.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^ meta.username.sql + +SET DEFAULT ROLE role FOR user@host +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ meta.username.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^ meta.username.sql + + +-- ---------------------------------------------------------------------------- +-- Show Create Event Statements +-- https://mariadb.com/kb/en/show-create-event +-- +-- SHOW CREATE EVENT event_name +-- ---------------------------------------------------------------------------- + +SHOW CREATE EVENT db_name.event_name +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ meta.event-name.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Show Create User Statements +-- https://mariadb.com/kb/en/show-create-user +-- ---------------------------------------------------------------------------- + +SHOW CREATE USER user_name +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ meta.username.sql + + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Show Grants Statements +-- https://mariadb.com/kb/en/show-grants +-- +-- SHOW CREATE USER user_name +-- ---------------------------------------------------------------------------- + +SHOW GRANTS +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.dml.sql +-- ^ - keyword + +SHOW GRANTS FOR user@host +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^ meta.username.sql + +SHOW GRANTS FOR role +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^ keyword.other.dml.sql +-- ^^^^ meta.username.sql + +SHOW GRANTS FOR CURRENT_USER; +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.user.sql + +SHOW GRANTS FOR CURRENT_USER(); +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.user.sql +-- ^^ meta.function-call.sql meta.group.sql + + +-- ---------------------------------------------------------------------------- +-- Join Syntax +-- https://mariadb.com/kb/en/join-syntax/ +-- +-- table_references: +-- table_reference [, table_reference] ... +-- +-- table_reference: +-- table_factor +-- | join_table +-- +-- table_factor: +-- tbl_name [PARTITION (partition_list)] +-- [query_system_time_period_specification] [[AS] alias] [index_hint_list] +-- | table_subquery [query_system_time_period_specification] [AS] alias +-- | ( table_references ) +-- | { ON table_reference LEFT OUTER JOIN table_reference +-- ON conditional_expr } +-- +-- join_table: +-- table_reference [INNER | CROSS] JOIN table_factor [join_condition] +-- | table_reference STRAIGHT_JOIN table_factor +-- | table_reference STRAIGHT_JOIN table_factor ON conditional_expr +-- | table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_condition +-- | table_reference NATURAL [{LEFT|RIGHT} [OUTER]] JOIN table_factor +-- +-- join_condition: +-- ON conditional_expr +-- | USING (column_list) +-- +-- query_system_time_period_specification: +-- FOR SYSTEM_TIME AS OF point_in_time +-- | FOR SYSTEM_TIME BETWEEN point_in_time AND point_in_time +-- | FOR SYSTEM_TIME FROM point_in_time TO point_in_time +-- | FOR SYSTEM_TIME ALL +-- +-- point_in_time: +-- [TIMESTAMP] expression +-- | TRANSACTION expression +-- +-- index_hint_list: +-- index_hint [, index_hint] ... +-- +-- index_hint: +-- USE {INDEX|KEY} +-- [{FOR {JOIN|ORDER BY|GROUP BY}] ([index_list]) +-- | IGNORE {INDEX|KEY} +-- [{FOR {JOIN|ORDER BY|GROUP BY}] (index_list) +-- | FORCE {INDEX|KEY} +-- [{FOR {JOIN|ORDER BY|GROUP BY}] (index_list) +-- +-- index_list: +-- index_name [, index_name] ... +-- +-- ---------------------------------------------------------------------------- + +JOIN (table1 alias, table2 AS alias ON (col1=col2), table3 PARTITION(part1) USE KEY (id), IGNORE INDEX (foo) USING (col1)) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.table-name.sql +-- ^^^^^ meta.alias.table.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.table.sql +-- ^^ keyword.control.conditional.sql +-- ^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.section.group.end.sql + +JOIN ( ( SELECT * FROM foo JOIN bar IGNORE KEY id ) alias, ( table1, ( SELECT * FROM baz) ) alias ) +-- ^^ meta.group.sql - meta.group meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql meta.group.sql +-- ^^^^^^^^ meta.group.sql - meta.group meta.group +-- ^^^^^^^^^^ meta.group.sql meta.group.sql - meta.group meta.group meta.group +-- ^^^^^^^^^^^^^^^^^^^^ meta.group.sql meta.group.sql meta.group.sql +-- ^^ meta.group.sql meta.group.sql - meta.group meta.group meta.group +-- ^^^^^^^^ meta.group.sql - meta.group meta.group +-- ^ - meta.group +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^ meta.table-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^ meta.table-name.sql +-- ^^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.table.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.table-name.sql +-- ^ punctuation.separator.sequence.sql + +-- ---------------------------------------------------------------------------- +-- table_reference +-- ---------------------------------------------------------------------------- + +INNER JOIN tbl_name PARTITION (part1, part2, part3) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN tbl_name AS alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN tbl_name PARTITION () alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.group.partitions.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN tbl_name PARTITION () AS alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.group.partitions.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN tbl_name FOR SYSTEM_TIME ALL alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^ constant.other.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN tbl_name FOR SYSTEM_TIME AS OF 20341 alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^ keyword.operator.logical.sql +-- ^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN tbl_name FOR SYSTEM_TIME FROM 20341 TO 423204 alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.operator.logical.sql +-- ^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN (SELECT * FROM tbl_name) alias USE KEY bar +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.table.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^ meta.column-name.sql + +INNER JOIN (SELECT * FROM tbl_name) PARTITION (part1, part2, part3) alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.table.sql + +INNER JOIN {ON tbl_name LEFT OUTER JOIN other1 other2 ON TRUE} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.mysql +-- ^^^^ keyword.other.dml.sql +-- ^ punctuation.section.braces.begin.mysql +-- ^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.table-name.sql +-- ^^^^^^ meta.alias.table.sql +-- ^^ keyword.control.conditional.sql +-- ^^^^ constant.language.boolean.true.sql +-- ^ punctuation.section.braces.end.mysql + +-- ---------------------------------------------------------------------------- +-- join_condition +-- ---------------------------------------------------------------------------- + +INNER JOIN tbl_name ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^ keyword.control.conditional.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name USING (col1, col2) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name alias USING (col1, col2) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ meta.alias.table.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name AS alias USING (col1, col2) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.table.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +-- ---------------------------------------------------------------------------- +-- index_hint +-- ---------------------------------------------------------------------------- + +FORCE INDEX FOR JOIN (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +FORCE INDEX FOR ORDER BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +FORCE INDEX FOR GROUP BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +USE INDEX FOR JOIN (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +USE INDEX FOR ORDER BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +USE INDEX FOR GROUP BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +SELECT * FROM table FORCE INDEX FOR GROUP BY (Name) +-- ^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +SELECT * FROM table USE INDEX FOR GROUP BY (Name) +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + + +-- ---------------------------------------------------------------------------- +-- Legacy Tests +-- ---------------------------------------------------------------------------- + +SELECT 'Foo Bar'; +-- ^^^^^^^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ punctuation.terminator.statement - string + +SELECT 'Foo '' Bar'; +-- ^^ constant.character.escape.sql + +SELECT "My "" Crazy Column Name" FROM my_table; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double +-- ^ punctuation.definition.string.begin +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end + +SELECT "My -- Crazy Column Name" FROM my_table; +-- ^^ - comment - punctuation + +SELECT "My /* Crazy Column Name" FROM my_table; +-- ^^ - comment - punctuation + +DROP TABLE IF EXISTS testing123; +-- <- meta.statement.drop.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +select * +from some_table +where exists(select * from other_table where id = some_table.id) +-- ^^^^^^ keyword.operator.logical + +SELECT +( +SELECT CASE field +USING a +-- <- keyword.other + WHEN 1 + THEN -- comment's say that +-- ^ comment.line.double-dash + EXISTS( + select 1) + ELSE NULL + END +) as result + + +/* +-- <- comment.block punctuation.definition.comment.begin +This is a +multiline comment +-- ^^^^^^^^^^^^^^^ source.sql comment.block.sql +*/ +-- <- comment.block punctuation.definition.comment.end + +/** + * +-- ^ punctuation.definition.comment.sql +*/ + +select + + + <=> +-- ^^^ keyword.operator.comparison.sql + +SELECT *, +-- ^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql + f.id AS database_id +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^ meta.alias.column +FROM foo +WHERE f.a IS NULL +-- ^^ keyword.other.dml.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql + AND f.b IS NOT NULL +-- ^^^ keyword.operator.logical.sql +-- ^^ keyword.operator.logical.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql + +CREATE INDEX IX_some_index ON dbo.some_table( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^ entity.name.struct.index +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin + some_column ASC +-- ^^^^^^^^^^^ meta.group meta.column-name +-- ^^^ meta.group keyword.other.order +) + +CREATE ALGORITHM=MERGE VIEW contactPersons( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^ constant.language +-- ^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^^ entity.name.struct.other +-- ^ meta.group punctuation.section.group.begin + customerName, +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence + firstName, + lastName, + phone +) AS +-- <- meta.group punctuation.section.group.end +-- ^ keyword.context.block - meta.group +SELECT +-- ^^^ keyword.other.dml + customerName, + contactFirstName, + contactLastName, + phone +FROM customers; +-- ^ keyword.other.dml +-- ^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE TEMPORARY TABLE IF NOT EXISTS foo ( +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^ entity.name.struct.table + bar NVARCHAR(400), + baz INT +); + +CREATE FUNCTION myFunction(id INT) RETURNS TABLE +BEGIN + RETURN SELECT * FROM board; +-- ^^^^^^ keyword.control.flow.return +END +-- <- keyword.control.flow.end + +INSERT INTO some_table (id, `from`, `to`, a, b) +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^^^^^^ meta.column-name.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.separator.sequence.sql +VALUES ( +-- <- keyword.other.dml.II.sql + :id, +-- ^^^ variable.parameter.sql +-- ^ punctuation.definition.variable.sql +-- ^ punctuation.separator.sequence.sql + :from, +-- ^^^^^ variable.parameter.sql +-- ^ punctuation.definition.variable.sql +-- ^ punctuation.separator.sequence.sql + :to, + :a, + :b +) +ON DUPLICATE KEY UPDATE +-- <- keyword.other.dml.sql +-- ^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql + a = :a, +-- ^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql + b = :b +-- ^ meta.column-name.sql +-- ^ keyword.operator +-- ^ variable.parameter.sql punctuation.definition.variable.sql +-- ^ variable.parameter.sql + +select @@hostname; +-- ^^ variable.language.sql punctuation.definition.variable.sql +-- ^^^^^^^^ variable.language.sql +-- ^ punctuation.terminator.statement.sql + +SELECT * +FROM suppliers +WHERE supplier_name LIKE 'H%\_'; +-- ^^^^ keyword.operator.logical.sql +-- ^^^^^^ meta.string.like.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^ - constant +-- ^ constant.other.wildcard.percent.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql +-- ^ punctuation.terminator.statement.sql + +SELECT * +FROM suppliers +WHERE supplier_name LIKE 'H%\__' ESCAPE '\\'; +-- ^^^^ keyword.operator.logical.sql +-- ^^^^^^ meta.string.like.sql string.quoted.single.sql +-- ^ - constant +-- ^ constant.other.wildcard.percent.sql +-- ^^ constant.character.escape.sql +-- ^ constant.other.wildcard.underscore.sql +-- ^^^^^^ keyword.operator.word.sql +-- ^ meta.string.escape.sql string.quoted.single.sql punctuation.definition.string.begin.sql +-- ^^ meta.string.escape.sql string.quoted.single.sql constant.character.escape.sql +-- ^ meta.string.escape.sql string.quoted.single.sql punctuation.definition.string.end.sql +-- ^ punctuation.terminator.statement.sql + +SELECT * +FROM suppliers +WHERE supplier_name LIKE 'H%\_#_' ESCAPE '#'; +-- ^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.string.like.sql string.quoted.single.sql +-- ^ - constant +-- ^ constant.other.wildcard.percent.sql +-- ^ - constant +-- ^ constant.other.wildcard.underscore.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql +-- ^^^^^^ keyword.operator.word.sql +-- ^ meta.string.escape.sql string.quoted.single.sql punctuation.definition.string.begin.sql +-- ^ meta.string.escape.sql string.quoted.single.sql constant.character.escape.sql +-- ^ meta.string.escape.sql string.quoted.single.sql punctuation.definition.string.end.sql +-- ^ punctuation.terminator.statement.sql + +LOCK TABLES trans READ, customer WRITE; +-- ^^^^^^^^ keyword.context.resource.mysql +-- ^^^^^ meta.table-name.sql +-- ^^^^ constant.language.lock-type.mysql +-- ^ punctuation.separator.sequence.mysql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ constant.language.lock-type.mysql +-- ^ punctuation.terminator.statement.sql +SELECT SUM(value) FROM trans WHERE customer_id=some_id; +UPDATE customer + SET total_value=sum_from_previous_statement + WHERE customer_id=some_id; +UNLOCK TABLES; +-- ^^^^^^^^^^ keyword.context.resource.mysql +-- ^ punctuation.terminator.statement.sql + +DESCRIBE City; +-- ^^^^^ meta.statement.show.sql keyword.other.dml.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.terminator.statement.sql +SHOW COLUMNS FROM City; +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^^^^^^^ keyword.other.mysql +-- ^^^^ keyword.other.mysql +-- ^^^^ meta.table-name.sql +-- ^ punctuation.terminator.statement.sql +SHOW FULL COLUMNS FROM mytable FROM mydb; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^^^^ keyword.other.mysql +-- ^^^^^^^ keyword.other.mysql +-- ^^^^ keyword.other.mysql +-- ^^^^^^^ meta.table-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^ punctuation.terminator.statement.sql + +SHOW EXTENDED COLUMNS FROM mydb.mytable; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.mysql +-- ^^^^^^^ keyword.other.mysql +-- ^^^^ keyword.other.mysql +-- ^^^^^^^^^^^^ meta.table-name.sql +-- ^ punctuation.terminator.statement.sql + +EXPLAIN FORMAT=JSON INTO @myselect +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^ variable.parameter.explain.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^ string.unquoted.mysql +-- ^^^^ keyword.other.dml.sql +-- ^ variable.other.sql punctuation.definition.variable.sql +-- ^^^^^^^^ variable.other.sql + SELECT name FROM a WHERE id = 2; +SELECT @myselect + +EXPLAIN FORMAT=TREE FOR SCHEMA s1 SELECT * FROM t WHERE c2 > 50; +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^ variable.parameter.explain.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^ string.unquoted.mysql +-- ^^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.other-name.sql +-- ^^^^^^ keyword.other.dml.sql +SELECT @@explain_format; +SET @@explain_format=TREE; + +EXPLAIN ANALYZE SELECT * FROM t1 JOIN t2 ON (t1.c1 = t2.c2); +EXPLAIN ANALYZE FORMAT=TREE SELECT * FROM t3 WHERE pk > 17; +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ variable.parameter.explain.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^ string.unquoted.mysql + +CREATE USER 'read' IDENTIFIED BY 'toor'; +GRANT SELECT ON * . * TO 'read'; +FLUSH PRIVILEGES; diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql new file mode 100644 index 0000000000..fc1cedd597 --- /dev/null +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -0,0 +1,553 @@ +-- SYNTAX TEST "Packages/SQL/PostgreSQL.sublime-syntax" + +CREATE TABLE test1 (a character(4)); +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^ entity.name.struct.table +-- ^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.terminator.statement +-- ^ punctuation.section.group.begin +-- ^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.section.group.end + +INSERT INTO test1 VALUES ('ok'); +SELECT a, char_length(a) FROM test1; +-- ^^^ keyword.other.dml +-- ^ meta.column-name - variable.other.member.declaration +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^ support.function +-- ^ meta.group punctuation.section.arguments.begin +-- ^ meta.group meta.column-name - variable.other.member.declaration +-- ^ meta.group punctuation.section.arguments.end +-- ^^^^ keyword.other.dml - meta.group +-- ^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE TABLE test2 (b varchar(5)); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^ entity.name.struct +-- ^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.terminator.statement +-- ^ punctuation.section.group.begin +-- ^ meta.column-name +-- ^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.section.group.end +INSERT INTO test2 VALUES ('ok'); +INSERT INTO test2 VALUES ('good '); +INSERT INTO test2 VALUES ('too long'); +#ERROR: value too long for type character varying(5) +INSERT INTO test2 VALUES ('too long'::varchar(5)); -- explicit truncation +-- ^^^^^^^^^^ string.quoted.single +-- ^^ keyword.operator.cast +-- ^^^^^^^^^^ storage.type +SELECT b, char_length(b) FROM test2; + +CREATE TABLE IF NOT EXISTS public.dropzone_details +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct +-- ^ punctuation.accessor.dot +( +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.begin + id uuid NOT NULL DEFAULT uuid_generate_v4(), +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^ meta.column-name +-- ^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^ meta.function-call support.function +-- ^ meta.function-call meta.group punctuation.section.arguments.begin +-- ^ meta.function-call meta.group punctuation.section.arguments.end +-- ^ punctuation.separator.sequence + name text COLLATE pg_catalog."default", + doc jsonb, +-- ^^^ meta.column-name variable.other.member.declaration +-- ^^^^^ storage.type +-- ^ punctuation.separator.sequence + poc json, +-- ^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.separator.sequence + size integer, +-- ^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^ punctuation.separator.sequence + CONSTRAINT id_name_uix UNIQUE (id, name) +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^ meta.column-name - variable.other.member.declaration +-- ^ punctuation.separator.sequence +-- ^^^^ meta.column-name +-- ^ punctuation.section.group.end +) + +-- https://www.postgresql.org/docs/current/datatype-binary.html#id-1.5.7.12.9 +SELECT '\xDEADBEEF'::bytea; +-- ^^^^^^^^^^ meta.string string.quoted.single constant.character.escape +-- ^ punctuation.definition.string.end +-- ^^ keyword.operator.cast +-- ^^^^^ storage.type +SET bytea_output = 'escape'; +SELECT 'abc \153\154\155 \052\251\124'::bytea; +-- ^^^^^^^^^^^^ constant.character.escape +-- ^^ keyword.operator.cast +-- ^^^^^ storage.type +-- ^ punctuation.terminator.statement + + +CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); +-- ^^^ meta.statement.create keyword.other.ddl +-- ^^^^ meta.statement.create keyword.other +-- ^^^^ meta.statement.create entity.name +-- ^^ keyword.context.block +CREATE TABLE person ( + name text, +-- ^^^^ meta.column-name variable.other.member.declaration +-- ^^^^ storage.type +-- ^ punctuation.separator.sequence + current_mood mood +-- ^^^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^ support.type +); +INSERT INTO person VALUES ('Moe', 'happy'); +SELECT * FROM person WHERE current_mood = 'happy'; + +CREATE TABLE test (a BIT(3), b BIT VARYING(5)); +INSERT INTO test VALUES (B'101', B'00'); +INSERT INTO test VALUES (B'10', B'101'); +INSERT INTO test VALUES (B'10'::bit(3), B'101'); + +CREATE TABLE sal_emp ( + name text, + pay_by_quarter integer[], +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.separator.sequence - storage + schedule text[][] +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^^^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +); + +INSERT INTO sal_emp + VALUES ('Bill', + '{10000, 10000, 10000, 10000}', + '{{"meeting", "lunch"}, {"training", "presentation"}}'); + +INSERT INTO sal_emp + VALUES ('Carol', + '{20000, 25000, 25000, 25000}', + '{{"breakfast", "consulting"}, {"meeting", "lunch"}}'); + +INSERT INTO sal_emp + VALUES ('Bill', + ARRAY[10000, 10000, 10000, 10000], +-- ^^^^^ keyword.declaration +-- ^ punctuation.section.brackets.begin +-- ^^^^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence +-- ^ punctuation.section.brackets.end +-- ^ punctuation.separator.sequence + ARRAY[['meeting', 'lunch'], ['training', 'presentation']]); +-- ^^^^^ keyword.declaration +-- ^^ punctuation.section.brackets.begin +-- ^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence - string + +INSERT INTO sal_emp + VALUES ('Carol', + ARRAY[20000, 25000, 25000, 25000], + ARRAY[['breakfast', 'consulting'], ['meeting', 'lunch']]); + +SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2]; +-- ^^^ keyword.other.dml +-- ^^^^ meta.column-name +-- ^^^^ keyword.other.dml +-- ^^^^^^^ meta.table-name +-- ^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement + +SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; +-- ^^^ keyword.other.dml +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ keyword.operator.range +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^^^^ keyword.other.dml +-- ^^^^^^^ meta.table-name + + +-- ---------------------------------------------------------------------------- +-- CREATE EXTENSION +-- https://www.postgresql.org/docs/current/sql-createextension.html +-- +-- CREATE EXTENSION [ IF NOT EXISTS ] extension_name +-- [ WITH ] [ SCHEMA schema_name ] +-- [ VERSION version ] +-- [ CASCADE ] +-- ---------------------------------------------------------------------------- + +CREATE EXTENSION hstore SCHEMA addons; +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^^^^ entity.name.namespace.psql +-- ^^^^^^ storage.modifier +-- ^^^^^^ meta.schema-name +-- ^ punctuation.terminator.statement + +CREATE EXTENSION IF NOT EXISTS extension_name WITH SCHEMA schema_name VERSION 1.0 CASCADE; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^ entity.name.namespace.psql +-- ^^^^ keyword.other.psql +-- ^^^^^^ storage.modifier.psql +-- ^^^^^^^^^^^ meta.schema-name.psql +-- ^^^^^^^ storage.modifier.psql +-- ^^^ meta.number.float.decimal.sql constant.numeric.value.sql +-- ^^^^^^^ storage.modifier.psql +-- ^ punctuation.terminator.statement.sql + +-- ----------------- +-- DROP EXTENSION +-- https://www.postgresql.org/docs/current/sql-dropextension.html +-- ----------------- + +DROP EXTENSION name CASCADE; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^ meta.extension-name.psql +-- ^^^^^^^ storage.modifier.psql +-- ^ punctuation.terminator.statement.sql + +DROP EXTENSION IF EXISTS name, second RESTRICT; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^ meta.extension-name.psql +-- ^ punctuation.separator.sequence.psql +-- ^^^^^^ meta.extension-name.psql +-- ^^^^^^^^ storage.modifier.psql +-- ^ punctuation.terminator.statement.sql + +-- ----------------- +-- ALTER EXTENSION +-- https://www.postgresql.org/docs/current/sql-alterextension.html +-- ----------------- + +ALTER EXTENSION extension_name UPDATE TO 1.2; +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.other.ddl.psql +-- ^^^ meta.number.float.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + +ALTER EXTENSION extension_name SET SCHEMA new_schema; +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^ keyword.other.ddl.psql +-- ^^^^^^ storage.modifier.psql +-- ^^^^^^^^^^ meta.schema-name.psql +-- + +ALTER EXTENSION extension_name ADD member_object; +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.member-name.psql +-- ^ punctuation.terminator.statement.sql + +ALTER EXTENSION extension_name DROP member_object; +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.member-name.psql + + +-- ----------------- +-- CREATE INDEX +-- https://www.postgresql.org/docs/current/sql-createindex.html +-- +-- CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON [ ONLY ] table_name [ USING method ] +-- ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass [ ( opclass_parameter = value [, ... ] ) ] ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] ) +-- [ INCLUDE ( column_name [, ...] ) ] +-- [ WITH ( storage_parameter [= value] [, ... ] ) ] +-- [ TABLESPACE tablespace_name ] +-- [ WHERE predicate ] +-- ----------------- + +CREATE INDEX index_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql + +CREATE INDEX index_name USING method_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^^^^ keyword.other + +CREATE UNIQUE INDEX IF NOT EXISTS index_name ON table_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^^^ meta.table-name.sql + +CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS index_name ON ONLY table_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^ keyword.other.psql +-- ^^^^^^^^^^ meta.table-name.sql + +CREATE UNIQUE INDEX CONCURRENTLY IF EXISTS index_name ON ONLY table_name USING method_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^ keyword.other.psql +-- ^^^^^^^^^^ meta.table-name.sql +-- ^^^^^ keyword.other + +CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.other +-- ^^^^^^^^^^^ meta.table-name +-- ^^^^^ keyword.other +-- ^^^ meta.function-call.sql support.function.sql + +-- ----------------- +-- CREATE TABLE +-- https://www.postgresql.org/docs/current/ddl-basics.html +-- ----------------- + +CREATE TABLE example_table ( + first_name VARCHAR(100) + CONSTRAINT check_first_name +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^ meta.constraint-name + ( first_name ~* '^[a-z]+$') +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^ meta.string.regexp +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ punctuation.section.group.end - meta.string +); + +ALTER TABLE mytable ADD CONSTRAINT verif_code CHECK (code IN ('A', 'AG', 'AL', 'AS', 'B', 'C', 'D', 'DA')); +-- <- meta.statement.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^^^ meta.table-name +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^^ keyword.other.ddl +-- ^^^^^^^^^^ meta.constraint-name +-- ^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^ meta.column-name + + +CREATE TABLE test1 ( + name varchar(500) NOT NULL PRIMARY KEY, + description varchar NOT NULL DEFAULT '', + authors varchar[], +); + +CREATE TABLE test2 ( + test1name varchar(500) NOT NULL REFERENCES test1(name) ON DELETE CASCADE ON UPDATE CASCADE, +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence + PRIMARY KEY(test1name) +); + +ALTER TABLE test2 ADD something varchar[]; +-- <- meta.statement.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter +-- ^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^ meta.table-name +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement + + +CREATE TRIGGER blah AFTER INSERT OR UPDATE +-- ^^^ keyword.other.ddl +-- ^^^^^^^ keyword.other +-- ^^^^ entity.name.struct.other +-- ^^^^^^^^^^^^^^^^^^^^^^ keyword.other + ON some_table FOR EACH ROW EXECUTE PROCEDURE some_procedure(); +-- ^^ keyword.other +-- ^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.function-call support.function + + +CREATE FUNCTION highlight_result_array(vals varchar[], something tsquery, something_else boolean) RETURNS varchar[] AS $$ +-- ^^^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^^ punctuation.section.block.begin +DECLARE +-- ^^^^ keyword.declaration.variable + output varchar[]; +-- ^ - variable +-- ^^^^^^ variable.other +-- ^ - variable - storage +-- ^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement +BEGIN +-- ^^ keyword.other.luw + FOR I IN array_lower(vals, 1)..array_upper(vals, 1) LOOP +-- ^^^ keyword.control.loop +-- ^ variable.other +-- ^^ keyword.operator.logical +-- ^^^^^^^^^^^ meta.function-call support.function +-- ^^ keyword.operator +-- ^^^^^^^^^^^ meta.function-call support.function +-- ^^^^ keyword.control.loop + output[I] := compute_result(vals[I], something, something_else); + END LOOP; +-- ^^^ keyword.control.loop +-- ^^^^ keyword.control.loop + RETURN output; +-- ^^^^^^ keyword.control.flow.return +END; +$$ LANGUAGE plpgsql STABLE; +-- <- punctuation.section.block.end +-- ^^^^^^^^ keyword.other +-- ^^^^^^^ constant.language +-- ^^^^^^ storage.modifier +-- ^ punctuation.terminator.statement + +DECLARE var varchar[]; +-- ^ - variable +-- ^^^ variable.other.psql +-- ^ - variable - storage + +DROP TRIGGER blah ON some_table; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop +-- ^ keyword.other.ddl +-- ^^^^^^^ keyword.other +-- ^^ keyword.other +-- ^^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +value := ts_headline(value, query, E'HighlightAll=TRUE, StartSel="\002", StopSel="\003"'); +-- ^^ punctuation.definition.string.begin +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single +-- ^^^^ constant.character.escape +-- ^^^^ constant.character.escape +-- ^ punctuation.definition.string.end +value := E'\u1234 \U9876A001' +-- ^^ keyword.operator.assignment +-- ^^^^^^ constant.character.escape +-- ^ - constant +-- ^^^^^^^^^^ constant.character.escape diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql new file mode 100644 index 0000000000..cced18ca18 --- /dev/null +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -0,0 +1,2697 @@ +-- SYNTAX TEST "Packages/SQL/TSQL.sublime-syntax" + +USE master +-- <- keyword.context - constant +-- ^^^^^^ meta.database-name + +SELECT columns FROM table WHERE + column LIKE '%[[]SQL Server Driver]%' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.other.wildcard.percent +-- ^^^ meta.set.like +-- ^ keyword.control.set.begin +-- ^ keyword.control.set.end +-- ^^^^^^^^^^^^^^^^^^ - constant - keyword +-- ^ constant.other.wildcard.percent +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE '%[SQL Server Driver]%' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.other.wildcard.percent +-- ^^^^^^^^^^^^^^^^^^^ meta.set.like +-- ^ keyword.control.set.begin +-- ^ keyword.control.set.end +-- ^^^^^^^^^^^^^^^ - constant - keyword +-- ^ constant.other.wildcard.percent +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE '%[^a-f]%' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.other.wildcard.percent +-- ^^^^^^ meta.set.like +-- ^ keyword.control.set.begin +-- ^ keyword.control.set.negation +-- ^ constant.other.range +-- ^ keyword.control.set.end +-- ^ constant.other.wildcard.percent +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE 'hello_world' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.other.wildcard.underscore +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE '%\[SQL Server Driver]^%\__' ESCAPE '\' +-- ^^^^ keyword.operator.logical +-- ^ constant.other.wildcard.percent +-- ^^ constant.character.escape +-- ^ - constant +-- ^ constant.other.wildcard.percent +-- ^^ constant.character.escape +-- ^ constant.other.wildcard.underscore +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end + +SELECT columns FROM table WHERE + column LIKE '%\[SQL Server Driver]^%\__' +-- ^^^^ keyword.operator.logical +-- ^ constant.other.wildcard.percent +-- ^^ constant.character.escape +-- ^ - constant +-- ^ constant.other.wildcard.percent +-- ^^ constant.character.escape +-- ^ constant.other.wildcard.underscore + ESCAPE '\' +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end + +SELECT columns FROM table WHERE + column LIKE '%\^[SQL Server Driver]^%_^_' ESCAPE '^' +-- ^^^^ keyword.operator.logical +-- ^ constant.other.wildcard.percent +-- ^ - constant +-- ^^ constant.character.escape +-- ^^ constant.character.escape +-- ^ constant.other.wildcard.underscore +-- ^^ constant.character.escape +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end + +SELECT columns FROM table WHERE + column LIKE '%\^[SQL Server Driver]^%_^_\_{{--' ESCAPE '{' -- uncatered for escape char, scope operators as though unescaped +-- ^^^^ keyword.operator.logical +-- ^ constant.other.wildcard.percent +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - constant.character.escape +-- ^^^^^^^^^^^^^^^^^^^ meta.set.like +-- ^^^^^^^^^^^ - meta.set +-- ^^ constant.other.wildcard +-- ^ constant.other.wildcard.underscore +-- ^ constant.other.wildcard.underscore +-- ^^^^^^^^^^^^^^^ - comment +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end +-- ^^ comment.line.double-dash punctuation.definition.comment + +DECLARE @Example INT = 5 +-- ^^^^ keyword.declaration.variable +-- ^^^^^^^^ variable.other.readwrite +-- ^^^ storage.type +-- ^ keyword.operator +-- ^ constant.numeric + +SELECT TOP 1 @Example = 4 FROM [dbo].[TableName] +-- ^^^ keyword.other.dml +-- ^^^ keyword.other.dml +-- ^ constant.numeric +-- ^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator +-- ^ constant.numeric +-- ^^^^ keyword.other.dml + +SELECT TOP(1) @Example = y FROM [dbo].[TableName] +-- ^^^ keyword.other.dml +-- ^^^ keyword.other.dml +-- ^ meta.group punctuation.section.parens.begin +-- ^ meta.group meta.number.integer.decimal constant.numeric.value +-- ^ meta.group punctuation.section.parens.end +-- ^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator +-- ^ meta.column-name +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^ meta.table-name + +SET @Path = 'X:\nowayout\' +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^ keyword.operator +-- ^^^^^^^^^^^^^^ string.quoted.single - constant +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ - string + +SET @Blah = 'He said, ''hello world''.' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ - string +-- ^^ constant.character.escape +-- ^^ constant.character.escape + +SET @Blah = CASE WHEN @x = 2 THEN 'Y' CASE WHEN @z = @x THEN 'N' ELSE NULL END +-- ^^^^ keyword.control.conditional.case +-- ^^^^ keyword.control.conditional.when +-- ^^ variable.other.readwrite +-- ^ keyword.operator.comparison +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.case +-- ^^^^ keyword.control.conditional.when +-- ^^ variable.other.readwrite +-- ^ keyword.operator.comparison +-- ^^ variable.other.readwrite +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.else +-- ^^^^ constant.language.null +-- ^^^ keyword.control.conditional.end +-- ^ - meta +SET @Blah = CASE @x WHEN 2 THEN 'Y' WHEN @z THEN 'N' ELSE NULL END +-- ^^^^ keyword.control.conditional.case +-- ^^ variable.other.readwrite +-- ^^^^ keyword.control.conditional.when +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.when +-- ^^ variable.other.readwrite +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.else +-- ^^^^ constant.language.null +-- ^^^ keyword.control.conditional.end +-- ^ - meta + + + +DECLARE @name SYSNAME -- database name +-- ^^^^ keyword.declaration.variable +-- ^ punctuation.definition.variable +-- ^^^^ variable.other.readwrite +-- ^^^^^^^ storage.type +-- ^^ comment.line.double-dash punctuation.definition.comment +DECLARE @path NVARCHAR(256) -- path for backup files +-- ^^^^ keyword.declaration.variable +-- ^ variable.other.readwrite punctuation.definition.variable +-- ^^^^ variable.other.readwrite +-- ^^^^^^^^^^^^^ storage.type +-- ^^^ constant.numeric +DECLARE @fileName NVARCHAR(256) -- filename for backup +DECLARE @fileDate VARCHAR(20) -- used for file name + +SET @path = 'C:\Backup\' + +SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) +-- ^ keyword.operator +-- ^^^^^^^ meta.function-call support.function.scalar +-- ^ meta.function-call meta.group punctuation.section.arguments.begin +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.separator +-- ^^^^^^^ support.function.scalar +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end +-- ^ punctuation.separator.arguments +-- ^^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.arguments.end +-- ^ - meta.function-call - meta.group + +DECLARE db_cursor CURSOR SCROLL DYNAMIC FOR +-- ^^^^ keyword.declaration.variable +-- ^^^^^^^^^ meta.cursor-name +-- ^^^^^^ support.type +-- ^^^^^^ storage.modifier +-- ^^^^^^^ storage.modifier +-- ^^^ keyword.other + SELECT name +-- ^^^^^^ keyword.other.dml +-- ^^^^ meta.column-name + FROM MASTER.dbo.sysdatabases + -- ^ keyword.other.dml + -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name + WHERE name NOT IN ('master','model','msdb','tempdb') + -- ^^ keyword.other.dml + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group + -- ^^^^^^^^ string.quoted.single + -- ^ punctuation.separator.sequence + -- ^^^^^^^ string.quoted.single + FOR UPDATE OF name +-- ^^^ meta.cursor-declaration keyword.other +-- ^^^^^^^^^ storage.modifier +-- ^^^^ meta.column-name +DECLARE @blah int +-- <- keyword.declaration.variable - meta.cursor-declaration + +OPEN db_cursor +-- ^ keyword.other +-- ^^^^^^^^^ meta.cursor-name +FETCH NEXT FROM db_cursor INTO @name +-- ^^^^^^^ keyword.other +-- ^^^^ keyword.other +-- ^^^^^^^^^ meta.cursor-name +-- ^^^^ keyword.other +-- ^^^^^ variable.other.readwrite + +WHILE @@FETCH_STATUS = 0 +-- ^^ keyword.control.loop +-- ^^^^^^^^^^^^^^ support.variable.global +-- ^^ support.variable.global +-- ^ keyword.operator.comparison +-- ^ meta.number.integer.decimal constant.numeric.value +BEGIN +-- ^^ keyword.control.flow.begin + SET @fileName = @path + @name + '_' + @fileDate + '.BAK' + BACKUP DATABASE @name TO DISK = @fileName +-- ^^^^^^^^^^^^^^^ keyword.other +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.other +-- ^^^^ keyword.other +-- ^ keyword.operator + + FETCH NEXT FROM db_cursor INTO @name +END +-- <- keyword.control.flow.end + +CLOSE db_cursor +-- ^^ keyword.other +-- ^^^^^^^^^ meta.cursor-name +DEALLOCATE db_cursor +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^ meta.cursor-name +GO +------- + +DECLARE db_cursor CURSOR FAST_FORWARD READ_ONLY FOR +-- ^^^^ keyword.declaration.variable +-- ^^^^^^^^^ meta.cursor-name +-- ^^^^^^ support.type +-- ^^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^ storage.modifier +-- ^^^ keyword.other + SELECT name +-- ^^^^^^ keyword.other.dml +-- ^^^^ meta.column-name + FROM MASTER.dbo.sysdatabases + -- ^ keyword.other.dml + -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name + WHERE name NOT IN ('master','model','msdb','tempdb') + -- ^^ keyword.other.dml + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group + -- ^^^^^^^^ string.quoted.single + -- ^ punctuation.separator.sequence + -- ^^^^^^^ string.quoted.single + +OPEN db_cursor +-- ^ keyword.other - meta.cursor-declaration +-- ^^^^^^^^^ meta.cursor-name + +------------- + +DECLARE @FileExists INT +SET NOCOUNT ON +--^ keyword.other.dml +-- ^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean +set nocount, xact_abort on +-- <- meta.statement.set keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set +-- ^^^^^^^ constant.language.switch +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean + +EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT +-- ^ keyword.control.flow.execute +-- ^ - meta.procedure-name +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ - meta.procedure-name +-- ^^^^^^^^^ variable.other.readwrite +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^ variable.other.readwrite +-- ^^^^^^ storage.modifier.output +SET NOCOUNT OFF +--^ keyword.other.dml +-- ^^^^^^^ constant.language.switch +-- ^^^ constant.language.boolean +IF @FileExists = 0 +BEGIN + RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) + RETURN -1 + -- ^^^ keyword.control.flow.return + -- ^ keyword.operator.arithmetic + -- ^ meta.number.integer.decimal constant.numeric.value +END + +SET @Message = 'Importing data from file...' +RAISERROR (@Message, 0, 1) WITH NOWAIT +-- ^^^^^^ meta.function-call support.function +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other + +SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 +-- ^^^^^^^^ meta.function-call support.function +-- ^^ keyword.operator.assignment.alias +-- ^^^^^^ meta.function-call support.function +------------------------------- +EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every 10 seconds', + @enabled=1, + @freq_type=4, + @freq_interval=1, + @freq_subday_type=2, + @freq_subday_interval=10, + @freq_relative_interval=0, + @freq_recurrence_factor=0, + @active_start_date=20150713, + @active_end_date=99991231, + @active_start_time=0, + @active_end_time=235959, + @schedule_uid=N'564354f8-4985-7408-80b7-afdc2bb92d3c' +IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback +-- <- keyword.control.conditional +-- ^^^^ keyword.control.flow.goto +-- ^ - meta.label-name +-- ^^^^^^^^^^^^^^^^ meta.label-name +-- ^ - meta.label-name +EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' +-- ^ keyword.control.flow.execute +-- ^^^^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback +COMMIT TRANSACTION +-- <- keyword.context +-- ^^^^^^^^^^^^^^^ keyword.context +GOTO EndSave +QuitWithRollback: +-- ^^^^^^^^^^^^^ entity.name.label +-- ^ punctuation.definition.label + IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION + -- ^^^^^^^^^^^ meta.group support.variable.global + -- ^ keyword.operator.comparison +EndSave: + +------------- + +INSERT INTO my_table (foo, bar) +-- ^^^^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^ - meta.function-call - support +-- ^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^ punctuation.section.group.end +VALUES (2, 'two'), +-- ^^^ keyword.other.dml.II +-- ^ punctuation.section.group.begin +-- ^ punctuation.section.group.end + (3, 'three') + +INSERT INTO #my_table +-- ^^^^^^^^ keyword.other.dml +-- ^^^^^^^^^ meta.table-name - meta.function-call - support +VALUES (2, 'two'), +-- ^^^ keyword.other.dml.II + (3, 'three') + + + +SELECT foo AS foobar, COUNT(*) AS tally +-- ^^^ keyword.other.dml +-- ^^^ meta.column-name +-- ^^ keyword.operator.assignment.alias +-- ^^^^^^ meta.alias.column +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.function-call +-- ^^^^^ support.function.aggregate +-- ^^^ meta.group +-- ^ punctuation.section.arguments.begin +-- ^ constant.other.wildcard.asterisk +-- ^ punctuation.section.arguments.end +-- ^^ keyword.operator.assignment.alias +-- ^^^^^ meta.alias.column +FROM bar +-- ^ keyword.other.dml +-- ^^^ meta.table-name +WHERE 1 = 1 +-- ^^ keyword.other.dml +GROUP BY foo +-- ^^^^^ keyword.other.dml + +select * +from (select * from some_table) alias_table WITH (NOLOCK) +-- ^ keyword.other.dml +-- ^ punctuation.section.group.begin +-- ^^^^^^ keyword.other.dml +-- ^ constant.other.wildcard.asterisk +-- ^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^^ meta.alias.table +-- ^^^^ keyword.other.dml +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.group constant.language.with +-- ^ punctuation.section.group.end +where exists(select * from other_table where id = some_table.id) +-- ^^^^^^ keyword.operator.logical + +UPDATE TableAlias +-- ^^^ keyword.other.dml +-- ^^^^^^^^^^ meta.table-name +SET column1 = v.column1, +-- <- keyword.other.dml +--^ keyword.other.dml + column2 = 'testing123 TODO: assert the = operator is scoped as assignment instead of comparison' +-- ^ keyword.operator + , col3 = 0xDEADC0DE +-- ^^^^^^^^^^ meta.number.integer.hexadecimal +-- ^^ constant.numeric.base +-- ^^^^^^^^ constant.numeric.value +FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) +-- ^ keyword.other.dml +-- ^ - meta.table-name +-- ^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.alias +-- ^^^^^^^^^^ meta.alias.table +-- ^ - meta.alias +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ - meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^ constant.language.with +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.group constant.language.with +-- ^ punctuation.section.group.end +INNER JOIN some_view AS AS WITH (NOLOCK) ON v.some_id = TableAlias.some_id +-- ^^^^^^^ keyword.other.dml +-- ^ - meta.table-name +-- ^^^^^^^^^ meta.table-name +-- ^ - meta.table-name +-- ^^ keyword.operator.assignment.alias +-- ^ - meta.alias +-- ^^ meta.alias.table +-- ^ - meta.alias +-- ^^^^ keyword.other.dml +-- ^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ constant.language.with +-- ^ punctuation.section.group.end +-- ^^ keyword.control.conditional +-- ^ - meta.column-name +-- ^^^^^^^^^ meta.column-name +-- ^ punctuation.accessor.dot +-- ^ - meta.column-name +-- ^ keyword.operator.comparison +-- ^ - meta.column-name +-- ^^^^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.accessor.dot +-- ^ - meta.column-name +WHERE TableAlias.some_id IN ( +-- ^^ keyword.other.dml +-- ^^ keyword.operator.logical +-- ^ meta.group punctuation.section.group.begin + SELECT a.another_id_column +-- ^^^^^^ keyword.other.dml + FROM dbname..table_name_in_default_schema a +-- ^^^^ keyword.other.dml +-- ^ - meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.alias +-- ^ meta.alias.table +-- ^ - meta.alias + WHERE a.another_id_column IS NOT NULL +-- ^^^^^ keyword.other.dml +-- ^ - meta.column-name - keyword +-- ^^^^^^^^^^^^^^^^^^^ meta.column-name +-- ^ - meta.column-name - keyword +-- ^^ keyword.operator.logical +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null + AND a.another_field IS NOT NULL +) +AND (v.column2 IS NULL OR ISNULL(TableAlias.column1, 0) != v.column1) +-- <- keyword.operator.logical +-- ^^ meta.group keyword.operator.logical +-- ^^^^^^ meta.function-call support.function +-- ^^ keyword.operator.comparison + +drop table foobar +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.statement.drop +-- ^ keyword.other.ddl +-- ^ - keyword +-- ^^^^^ keyword.other +-- ^^^^^^ meta.table-name + +alter table foo +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^ meta.statement.alter meta.table-name +add bar uniqueidentifier +--^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +--^ keyword.other.ddl.sql +-- ^^^ meta.column-name +-- ^^^^^^^^^^^^^^^^ storage.type + +alter table foo +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^ meta.table-name +alter column bar uniqueidentifier not null +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^ meta.column-name +-- ^^^^^^^^^^^^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null + +USE AdventureWorks2012; +GO +SELECT i.ProductID, p.Name, i.LocationID, i.Quantity + ,RANK() OVER (PARTITION BY i.LocationID ORDER BY i.Quantity DESC) AS Rank +-- ^ punctuation.separator.sequence +-- ^^^^ meta.function-call support.function +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^ meta.group keyword.other +-- ^^^^^^^^ meta.group keyword.other.dml +-- ^^^^ meta.group keyword.other.order +-- ^^ keyword.operator.assignment.alias +-- ^^^^ meta.alias.column +FROM Production.ProductInventory AS i +INNER JOIN Production.Product AS p + ON i.ProductID = p.ProductID +WHERE i.LocationID BETWEEN 3 AND 4 +-- ^^ keyword.other.dml +-- ^^^^^^^ keyword.operator.logical +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^^^ keyword.operator.logical +-- ^ meta.number.integer.decimal constant.numeric.value +ORDER BY i.LocationID; + +PRINT 'Record with ID ' + CAST(@RecordID AS VARCHAR(10)) + ' has been updated.' +-- ^^ support.function.tsql +-- ^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ keyword.operator.arithmetic +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^ support.function +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.section.arguments.end + +UPDATE foo +SET Value = Bar.Value +FROM foo +INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND ISNULL(bar.some_id, 0) = ISNULL(foo.some_id, 0) +-- ^^^^^^^ keyword.other.dml +-- ^^^ meta.table-name +-- ^^^^^^ meta.group invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql +-- ^^ keyword.control.conditional +-- ^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ support.constant +-- ^^^ keyword.operator.logical +-- ^^^^^^ meta.function-call support.function +-- ^ keyword.operator.comparison +-- ^^^^^^ meta.function-call support.function + AND foo.a = '' +-- ^^^ keyword.operator.logical +-- ^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^ string.quoted.single + +SELECT DISTINCT * +INTO ##global_temp_table +-- ^ keyword.other.dml +-- ^^ meta.table-name.sql punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^^^^ meta.table-name - punctuation +FROM some_long_table_name s +LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL(p.ok, '') = ISNULL(a.ok, '') COLLATE DATABASE_DEFAULT +-- ^^^^^^^^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^^^^^ invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql +-- ^ meta.alias.table +-- ^^ keyword.control.conditional +-- ^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^ meta.column-name +-- ^^^ keyword.operator.logical +-- ^^^^^^ meta.function-call support.function +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ support.constant + +----------- + +USE MSSQLTipsDemo +GO + +CREATE OR ALTER PROC CreateOrAlterDemo +-- ^^^^^^^^^^^^ meta.statement.create keyword.other.ddl +-- ^^^^ meta.statement.create keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql entity.name.function.sql + @Count SMALLINT +,@Other INT OUTPUT +-- <- punctuation.separator.sequence +--^^^^^ variable.parameter +-- ^^^ storage.type +-- ^^^^^^ storage.modifier.output +AS +-- <- keyword.context.block +BEGIN +-- <- keyword.control.flow.begin + SELECT TOP (@Count) * FROM [dbo].[CountryInfoNew] +-- ^^^^^^ keyword.other.dml +-- ^^^ keyword.other.dml +-- ^ meta.group punctuation.section.group.begin +-- ^ meta.group variable.other.readwrite punctuation.definition.variable +-- ^^^^^ meta.group variable.other.readwrite +-- ^ meta.group punctuation.section.group.end +-- ^ constant.other.wildcard.asterisk +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end +-- ^ punctuation.accessor.dot +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end + +END +-- <- keyword.control.flow.end +GO +-- <- keyword.control.flow.go + +--------------- +ALTER PROC CreateOrAlterDemo +-- ^^ meta.statement.alter keyword.other.ddl +-- ^^^^ meta.statement.alter keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^ meta.procedure-name + @Count SMALLINT +,@Other INT OUTPUT +-- <- punctuation.separator.sequence +--^^^^^ variable.parameter +-- ^^^ storage.type +-- ^^^^^^ storage.modifier.output +AS +-- <- keyword.context.block +BEGIN +-- <- keyword.control.flow.begin +END +-- <- keyword.control.flow.end +--- + +select A.A + , CASE WHEN B.B IS NOT NULL THEN B.B ELSE DATEADD(d, 1 - DATEPART(d, GETDATE()), DATEADD(m, B.MonthsInFuture, DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))) END AS FirstDayOfFutureMonth + -- ^ constant.language.tsql +-- ^ punctuation.separator.sequence +-- ^^^^ keyword.control.conditional.case + , B.* +-- ^ punctuation.separator.sequence +-- ^^ meta.column-name +-- ^ punctuation.accessor.dot +-- ^ constant.other.wildcard.asterisk +into #temp +-- ^ keyword.other.dml +-- ^^^^^ meta.table-name +from @A A +-- ^ keyword.other.dml +-- ^ meta.table-name.sql variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^ meta.table-name.sql variable.other.readwrite.sql +-- ^ meta.alias.table +inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID +--^^^^^^^^ keyword.other.dml +-- ^ meta.table-name +-- ^^ keyword.control.conditional +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ keyword.other.dml +-- ^ keyword.operator.comparison +-- ^^^^ meta.column-name + +WITH Sales_CTE (SalesPersonID, TotalSales, SalesYear) +-- ^ keyword.other.dml +-- ^^^^^^^^^ meta.cte-table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name +AS +-- <- keyword.operator.assignment.cte +-- Define the first CTE query. +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-dash +( +-- <- meta.group punctuation.section.group.begin + SELECT SalesPersonID, SUM(TotalDue) AS TotalSales, YEAR(OrderDate) AS SalesYear +-- ^^^^^^ meta.group keyword.other.dml + FROM Sales.SalesOrderHeader + WHERE SalesPersonID IS NOT NULL + GROUP BY SalesPersonID, YEAR(OrderDate) + +) +, -- Use a comma to separate multiple CTE definitions. +-- <- punctuation.separator.sequence.cte +-- Define the second CTE query, which returns sales quota data by year for each sales person. +Sales_Quota_CTE (BusinessEntityID, SalesQuota, SalesQuotaYear) +-- ^^^^^^^^^^^^ meta.cte-table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns - meta.group meta.group +-- ^^^^^^^^^^^^^^^^ meta.column-name +AS +-- <- keyword.operator.assignment.cte +( +-- <- meta.group punctuation.section.group.begin + SELECT BusinessEntityID, SUM(SalesQuota)AS SalesQuota, YEAR(QuotaDate) AS SalesQuotaYear +-- ^^^^^^ meta.group keyword.other.dml + FROM Sales.SalesPersonQuotaHistory + GROUP BY BusinessEntityID, YEAR(QuotaDate) +) + +-- Define the outer query by referencing columns from both CTEs. +SELECT SalesPersonID +-- ^^^ keyword.other.dml + , SalesYear + , FORMAT(TotalSales,'C','en-us') AS TotalSales + , SalesQuotaYear + , FORMAT (SalesQuota,'C','en-us') AS SalesQuota + , FORMAT (TotalSales -SalesQuota, 'C','en-us') AS Amt_Above_or_Below_Quota +FROM Sales_CTE +JOIN Sales_Quota_CTE ON Sales_Quota_CTE.BusinessEntityID = Sales_CTE.SalesPersonID + AND Sales_CTE.SalesYear = Sales_Quota_CTE.SalesQuotaYear +ORDER BY SalesPersonID, SalesYear; + +WITH DirectReports(ManagerID, EmployeeID, Title, EmployeeLevel) AS +( + SELECT ManagerID, EmployeeID, Title, 0 AS EmployeeLevel + FROM dbo.MyEmployees + WHERE ManagerID IS NULL + UNION ALL + SELECT e.ManagerID, e.EmployeeID, e.Title, EmployeeLevel + 1 + FROM dbo.MyEmployees AS e + INNER JOIN DirectReports AS d + ON e.ManagerID = d.EmployeeID +) +SELECT ManagerID, EmployeeID, Title, EmployeeLevel +FROM DirectReports +ORDER BY ManagerID +OPTION (MAXRECURSION 3) +-- ^^^ keyword.other.dml +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group constant.language.with +-- ^ meta.group constant.language.with +-- ^ meta.group punctuation.section.group.end + +WITH cte_table AS ( SELECT blah ) +-- ^ keyword.other.dml +-- ^^^^^^^^^ meta.cte-table-name +-- ^^ keyword.operator.assignment.cte +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^ meta.group keyword.other.dml +-- ^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end +SELECT cte_table.* FROM cte_table +-- ^^^ keyword.other.dml +-- ^^^^^^^^^^ meta.column-name +-- ^ constant.other.wildcard.asterisk +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^ meta.table-name + +;WITH A AS + ( + SELECT + Foo.ID AS [FooID], + Character, + Universe, + COUNT(Bar.*) AS BarCount + FROM + Foo + LEFT JOIN Bar B WITH (NOLOCK) ON B.Something = 1 AND B.Example = Foo.Example AND B.[When] >= @intervalDate_Start AND B.[When] < @intervalDate_End + WHERE + @intervalDate_Start <= Foo.CreationTime AND Foo.CreationTime < @intervalDate_End + GROUP BY + ISNULL(Foo.Example, Foo.ID) + ), + B AS +-- ^ meta.cte-table-name +-- ^^ keyword.operator.assignment.cte + ( + SELECT +-- ^^^^^^ meta.group keyword.other.dml + FooID, + CASE WHEN Character = 'Zoidberg' + THEN + CASE WHEN SUBSTRING(Universe, 1, 3) IN ('140', '170','290','235') + THEN 'Futurama' + ELSE 'Pasturama' + END + ELSE Universe + END AS Universe, + BarCount + FROM + A a + ) + SELECT + * + FROM + B + ORDER BY Universe DESC + + +CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^^ entity.name.struct +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns +-- ^ punctuation.section.group.begin +-- ^^ meta.column-name +-- ^^^^^ storage.type +-- ^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.section.group.end +GO +-- <- keyword.control.flow.go +CREATE TABLE foo ([int] [int] PRIMARY KEY, [test'hello¬world'@"me"] [varchar] (5)); +-- ^^^^^ storage.type +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name + +CREATE PROCEDURE [blah].[test] + @input1 INT, + @input2 [VARCHAR]( MAX ) +-- ^^^^^^^^^^^^^^^^ storage.type +-- ^^^ constant.language.max +AS +-- <- keyword.context.block +;WITH CTE AS (SELECT @input1 AS Input1) UPDATE Blah SET X = CTE.Input1 FROM CTE JOIN X ON X.Nonsense = 12.6 +-- <- punctuation.terminator.statement +--^^^ keyword.other.dml +-- ^^^ meta.cte-table-name +-- ^^ keyword.operator.assignment.cte +-- ^^^^^^ keyword.other.dml +-- ^^^^ meta.table-name +-- ^^^ keyword.other.dml +-- ^^^^ meta.number.float.decimal constant.numeric.value +-- ^ punctuation.separator.decimal + +IF OBJECT_ID('tempdb..import') IS NOT NULL + DROP TABLE tempdb..import + -- ^^^^^^^^^^^^^^ meta.table-name + -- ^^ punctuation.accessor.dot +GO +CREATE TABLE tempdb..[import] (a varchar(10), b varchar(20) null) +GO +RAISERROR ('importing file...', 0, 1) WITH NOWAIT +-- import file +BULK INSERT +--^^^^^^^^^ keyword.other + tempdb..import +FROM + 'C:\temp_folder\filename.txt' +WITH ( + FIRSTROW = 1, +-- ^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence + FIELDTERMINATOR = ';', + ROWTERMINATOR = '\n', +-- ^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^^ string.quoted.single +-- ^ punctuation.separator.sequence + CODEPAGE = '1257', + TABLOCK +-- ^^^^^^^ constant.language.with +) +-- <- punctuation.section.group.end +IF @@ERROR != 0 +-- <- keyword.control.conditional +-- ^^^^^^^ support.variable.global +-- ^^ keyword.operator.comparison + UPDATE tempdb..continue_script SET proceed = 0 +GO +IF EXISTS (SELECT proceed FROM tempdb..continue_script WHERE proceed = 0) + RETURN +RAISERROR ('file imported', 0, 1) WITH NOWAIT + +--------- + +SELECT [EmpID] + ,[FirstName] + ,[LastName] + ,[Education] + ,[Occupation] + ,[YearlyIncome] + ,[Sales] + ,[HireDate] + FROM [NewEmployee] + FOR XML RAW, ELEMENTS; +-- ^^^^^^ keyword.other +-- ^^^ keyword.other +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ keyword.other + +SELECT [EmpID] + ,[FirstName] + ,[LastName] + ,[Education] + ,[Occupation] + ,[YearlyIncome] + ,[Sales] + ,[HireDate] + FROM [NewEmployee] + FOR XML RAW('Employee'), +--^^^^^^^ keyword.other +-- ^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence + ROOT('EmployeeDetails'), ELEMENTS XSINIL, XMLSCHEMA('urn:tutorialgateway.org'); +-- ^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ keyword.other +-- ^^^^^^ keyword.other +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ keyword.other +------------------------ + +USE [AdventureWorks] +GO +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (INDEX = IX_ProductReview_ProductID_Name) +-- ^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.index-name +INNER JOIN [Production].[Product] PP +WITH (INDEX = [AK_Product_Name]) ON PR.ProductID = PP.ProductID +-- ^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^ meta.index-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end + +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (TABLOCK, INDEX(myindex, [anotherindex])) +-- ^^^^^^^ constant.language.with +-- ^ punctuation.separator.sequence +-- ^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.index-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^ meta.index-name +-- ^^ punctuation.section.group.end + +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (TABLOCK, INDEX(1)) +-- ^^^^^ keyword.other +-- ^^^ meta.group meta.group +-- ^ meta.number.integer.decimal constant.numeric.value + +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (FORCESEEK (MyIndex (col1, col2, col3)) +-- ^^^^^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.index-name +-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.section.group.begin +-- ^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^ punctuation.section.group.end +----------------- + + +-- Pivot table with one row and five columns +SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, + [0], [1], [2], [3], [4] +--^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^ meta.column-name +FROM +( + SELECT DaysToManufacture, StandardCost + FROM Production.Product +) AS SourceTable +PIVOT +--^^^ keyword.other +( + AVG(StandardCost) +--^^^^^^^^^^^^^^^^^ meta.function-call +--^^^ support.function.aggregate +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.arguments.end + FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) +--^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.column-name +-- ^^ keyword.operator.logical +-- ^ punctuation.section.group.begin +-- ^^^ meta.column-name +-- ^ punctuation.separator.sequence +) AS PivotTable; +--^^ keyword.operator.assignment.alias +-- ^^^^^^^^^^ meta.alias.table +-- ^ punctuation.terminator.statement + +SELECT item.ID AS DatePivotID, + MAX(dDate) AS LastUpdateDate +FROM Documents +UNPIVOT (dDate FOR nDate IN (date1, date2, date3, date4)) AS item +-- <- keyword.other +-- ^^^^ keyword.other +-- ^^ keyword.operator.assignment.alias +-- ^^^^ meta.alias.table +GROUP BY item.ID +-- ^^^^^ keyword.other.dml + +------------ +-- Create the table and insert values as portrayed in the previous example. +CREATE TABLE pvt (VendorID INT, Emp1 INT, Emp2 INT, + Emp3 INT, Emp4 INT, Emp5 INT); +GO +INSERT INTO pvt VALUES (1,4,3,5,4,4); +INSERT INTO pvt VALUES (2,4,1,5,5,5); +INSERT INTO pvt VALUES (3,4,3,5,4,4); +INSERT INTO pvt VALUES (4,4,2,5,5,4); +INSERT INTO pvt VALUES (5,5,1,5,5,5); +GO +-- Unpivot the table. +SELECT VendorID, Employee, Orders +FROM + (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 + FROM pvt) p +UNPIVOT +-- <- keyword.other +--^^^^^ keyword.other + (Orders FOR Employee IN +-- ^^^^^^ meta.column-name +-- ^^^ keyword.other +-- ^^^^^^^^ meta.column-name +-- ^^ keyword.operator.logical + (Emp1, Emp2, Emp3, Emp4, Emp5) +) AS unpvt; +-- <- meta.group punctuation.section.group.end +--^^ keyword.operator.assignment.alias +-- ^^^^^ meta.alias.table +-- ^ punctuation.terminator.statement +GO + +------------- + +CREATE TABLE dbo.T1 ( column_1 int IDENTITY, column_2 VARCHAR(30)); +GO +INSERT T1 VALUES ('Row #1'); +--^^^^ keyword.other.dml +-- ^^ meta.table-name +-- ^^^^^^ keyword.other.dml.II +INSERT T1 (column_2) VALUES ('Row #2'); +GO +SET IDENTITY_INSERT T1 ON; +-- <- keyword.other.dml +-- ^^^^^^^^^^^^^^^ constant.language.switch +-- ^^ meta.table-name +-- ^^ constant.language.boolean +-- ^ punctuation.terminator.statement +GO +INSERT INTO T1 (column_1,column_2) + VALUES (-99, 'Explicit identity value'); +GO +SELECT column_1, column_2 +FROM T1; +GO + +CREATE TABLE dbo.T1 +( +-- <- meta.group.table-columns punctuation.section.group.begin + column_1 AS 'Computed column ' + column_2, +-- ^^^^^^^^ meta.column-name +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.computed-column-definition +-- ^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ keyword.operator.arithmetic +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence - meta.computed-column-definition + column_2 varchar(30) +-- ^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^ storage.type + CONSTRAINT default_name DEFAULT ('my column default'), +-- ^^^^^^^^^^ storage.modifier +-- ^ - meta.constraint-name +-- ^^^^^^^^^^^^ meta.constraint-name +-- ^ - meta.constraint-name +-- ^^^^^^^ storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence + column_3 rowversion, +-- ^ - meta.column-name +-- ^^^^^^^^ meta.column-name +-- ^ - meta.column-name +-- ^^^^^^^^^^ storage.type + column_4 varchar(40) NULL, +-- ^ - meta.column-name +-- ^^^^^^^^ meta.column-name +-- ^ - meta.column-name +-- ^^^^^^^^^^^ storage.type +-- ^^^^ constant.language.null +-- ^ punctuation.separator.sequence + column_5 as 'last computed' + column_2 +-- ^ - meta.column-name +-- ^^^^^^^^ meta.column-name +-- ^^^ - meta.column-name - meta.computed-column-definition +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.computed-column-definition +-- ^^ keyword.other.tsql +-- ^^^^^^^^^^^^^^^ string.quoted.single +-- ^ keyword.operator.arithmetic +-- ^^^^^^^^ meta.column-name.sql +); +-- <- meta.group.table-columns punctuation.section.group.end +INSERT INTO T1 DEFAULT VALUES; +-- ^^^^^^^^ keyword.other.dml +-- ^^ meta.table-name +-- ^^^^^^^^^^^^^^ keyword.other.dml.II +-- ^ punctuation.terminator.statement + + +MERGE sales.category t +-- ^^ keyword.other +-- ^ - meta.table-name +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.alias +-- ^ meta.alias.table +-- ^ - meta.alias + USING sales.category_staging s +-- ^^^^^ keyword.context.resource.tsql +-- ^ - meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.alias +-- ^ meta.alias.table +-- ^ - meta.alias +ON (s.category_id = t.category_id) +-- <- keyword.control.conditional +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^^^^^^^^ meta.column-name +WHEN MATCHED +-- ^^^^^^^^^ keyword.control.conditional.case + THEN UPDATE SET +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other.dml +-- ^^^ keyword.other.dml + t.category_name = s.category_name, +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ keyword.operator +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence + t.amount = s.amount +-- ^^^^^^^^ meta.column-name +-- ^ keyword.operator +-- ^^^^^^^^ meta.column-name +WHEN NOT MATCHED BY TARGET +--^^^^^^^^^^^^^^ keyword.control.conditional.case +-- ^^^^^^^^^ keyword.other + THEN INSERT (category_id, category_name, amount) +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.group.end + VALUES (s.category_id, s.category_name, s.amount) +-- ^^^^^^ keyword.other.dml.II +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +WHEN NOT MATCHED BY SOURCE +--^^^^^^^^^^^^^^ keyword.control.conditional.case +-- ^^^^^^^^^ keyword.other + THEN DELETE; +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other.dml +-- ^ punctuation.terminator.statement + +-------------- +SET ANSI_NULLS ON +-- ^^^^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean +GO +SET QUOTED_IDENTIFIER ON +-- ^^^^^^^^^^^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean +GO +CREATE TABLE [dbo].[be_Categories]( + [CategoryID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_be_Categories_CategoryID] DEFAULT (newid()), +-- ^^^^^^^^^^ storage.modifier +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^^ storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^ meta.function-call support.function +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence + [CategoryName] [nvarchar](50) NULL, + [Description] [nvarchar](200) NULL, + [ParentID] [uniqueidentifier] NULL, + CONSTRAINT [PK_be_Categories] PRIMARY KEY CLUSTERED +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^ storage.modifier + ( + [CategoryID] ASC +-- ^^^^^^^^^^^^ meta.column-name +-- ^^^ keyword.other.order + ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^ constant.language.boolean +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.boolean +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.boolean +-- ^ punctuation.section.group.end +-- ^^ keyword.other +-- ^^^^^^^^^ meta.filegroup-name +) ON [PRIMARY] +-- <- punctuation.section.group.end +--^^ meta.statement.create keyword.other +-- ^^^^^^^^^ meta.filegroup-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end +GO +-------------- +CREATE TABLE [dbo].[table_with_constraint_following_derived_column]( + [SomeID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_be_Categories_CategoryID] DEFAULT (newid()), + [Data] [nvarchar](MAX) NOT NULL, + [DerivedColumn1] AS CAST(JSON_VALUE([Data], '$.info.address.PostCode') AS NVARCHAR(1000)) +-- ^^^^^^^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.computed-column-definition meta.function-call +-- ^^^^ support.function +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^^ support.function +-- ^ punctuation.section.arguments.begin +-- ^^^^^^ meta.group meta.function-call meta.group meta.column-name +-- ^ meta.group meta.function-call meta.group punctuation.separator.arguments +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.arguments.end +-- ^^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^ storage.type +-- ^ punctuation.section.arguments.end + CONSTRAINT [PK_be_Categories] PRIMARY KEY CLUSTERED +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^ storage.modifier + ( + [CategoryID] ASC +-- ^^^^^^^^^^^^ meta.column-name +-- ^^^ keyword.other.order + ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^ constant.language.boolean +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.boolean +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.boolean +-- ^ punctuation.section.group.end +-- ^^ keyword.other +-- ^^^^^^^^^ meta.filegroup-name +) ON [PRIMARY] +-- <- punctuation.section.group.end +--^^ meta.statement.create keyword.other +-- ^^^^^^^^^ meta.filegroup-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end +GO +-------------- +CREATE TABLE [Employee]( + [EmployeeID] [int] NOT NULL PRIMARY KEY, +-- ^^^^^^^^^^^^ meta.column-name +-- ^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence + [FirstName] VARCHAR(250) NOT NULL, + [LastName] VARCHAR(250) NOT NULL, + [DepartmentID] [int] NOT NULL REFERENCES [Department](DepartmentID), +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence +) ON [PRIMARY] +-- <- punctuation.section.group.end +--^^ meta.statement.create keyword.other +-- ^^^^^^^^^ meta.statement.create meta.filegroup-name +GO +SELECT * FROM Department D +CROSS APPLY +--^^^^^^^^^ keyword.other.dml + ( + SELECT * FROM Employee E + WHERE E.DepartmentID = D.DepartmentID + ) A +GO +SELECT * FROM Department D +OUTER APPLY +-- ^^^^^^^^ keyword.other.dml + ( + SELECT * FROM Employee E + WHERE E.DepartmentID = D.DepartmentID + ) A +GO +-------------------- +IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[fn_GetAllEmployeeOfADepartment]') AND type IN (N'IF')) +BEGIN + DROP FUNCTION dbo.fn_GetAllEmployeeOfADepartment -- TODO: scope this correctly +END +GO + +CREATE FUNCTION dbo.fn_GetAllEmployeeOfADepartment(@DeptID AS INT) +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.parameters.sql meta.group.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^ keyword.context.tsql +-- ^^^ storage.type.sql +RETURNS TABLE +--^^^^^ keyword.other +-- ^^^^^ storage.type +AS +-- <- keyword.context.block +RETURN +-- ^^^ keyword.control.flow.return + ( + SELECT * FROM Employee E + WHERE E.DepartmentID = @DeptID + ) +GO + +CREATE FUNCTION foo() RETURNS @MyType +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.function.sql +-- ^^ meta.group.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ support.type.sql variable.other.readwrite.sql + +CREATE FUNCTION foo() RETURNS My@TypeName +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.function.sql +-- ^^ meta.group.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^ support.type.sql - variable +-- ^^^^^^^^^ support.type.sql variable.other.readwrite.sql + +CREATE TYPE some_type AS TABLE ( +-- ^^^^^^^^^ entity.name.struct.other.sql +-- ^^ keyword.context.block.sql +-- ^^^^^ support.type.sql +-- ^ meta.group.table-columns.sql punctuation.section.group.begin.sql + some_id int, +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.group.table-columns.sql +-- ^^^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql + some_text varchar(64) +); + +CREATE FUNCTION dbo.select_something (@input some_type READONLY) RETURNS TABLE +-- ^^^^^^ variable.parameter.sql - support +-- ^^^^^^^^^ support.type.sql +-- ^^^^^^^^ storage.modifier.tsql - support + RETURN SELECT * FROM @input +-- ^^^^^^ keyword.context.block.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^ meta.table-name.sql variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^^^^^ meta.table-name.sql variable.other.readwrite.sql +; + + +CREATE FUNCTION dbo.select_something_else (@input int, @another_input char(2)) RETURNS TABLE +-- ^ variable.parameter.sql punctuation.definition.variable.tsql +-- ^^^^^ variable.parameter.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^^^^^^^ storage.type.sql + RETURN SELECT @input, @another_input +; + +SELECT * FROM Department D +CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_results_table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-valued-function-name +-- ^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.arguments.end +-- ^^ keyword.operator.assignment.alias - meta.function-call +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.alias.table +GO + +SELECT * FROM Department D +OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID, 123, 'testing123') +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name +-- ^ meta.function-call meta.group punctuation.section.arguments.begin +-- ^^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name +-- ^ meta.function-call meta.group punctuation.separator.arguments +-- ^^^ meta.function-call meta.group meta.number.integer.decimal constant.numeric.value +-- ^ meta.function-call meta.group punctuation.separator.arguments +-- ^^^^^^^^^^^^ meta.function-call meta.group string.quoted.single +-- ^ meta.function-call meta.group punctuation.section.arguments.end +GO + +SELECT DB_NAME(r.database_id) AS [Database], st.[text] AS [Query] +FROM sys.dm_exec_requests r +CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name +-- ^ meta.function-call meta.group punctuation.section.arguments.begin +-- ^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name +-- ^ meta.function-call meta.group punctuation.section.arguments.end +-- ^^ meta.alias.table +WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. +AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^ support.variable.global +-- ^^ punctuation.definition.variable +-- ^ meta.group punctuation.section.group.end + +SELECT p.BusinessEntityID , + p.FirstName , + p.MiddleName , + p.LastName , + pp.PhoneNumber , + dbo.some_func(p.BusinessEntityID), +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^^^ variable.function +-- ^ punctuation.accessor.dot + [dbo].[some_func](p.BusinessEntityID) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^^^^^^^ variable.function +-- ^ punctuation.accessor.dot +FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) +-- ^ meta.alias.table +-- ^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^^ meta.group.tablesample +-- ^ punctuation.section.group.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^^^^^^^ constant.language +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^ constant.language +-- ^ meta.group punctuation.section.group.begin +-- ^^^ meta.group meta.number.integer.decimal constant.numeric.value +-- ^ meta.group punctuation.section.group.end + LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE SYSTEM (10 ROWS) +-- ^^ meta.alias.table +-- ^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^ meta.group.tablesample +-- ^ punctuation.section.group.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^^^^ constant.language +-- ^ punctuation.section.group.end + ON pp.BusinessEntityID = p.BusinessEntityID +-- ^^ keyword.control.conditional +-- ^^^^^^^^^^^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^^^^^ meta.column-name +ORDER BY p.BusinessEntityID DESC; + +-- Test incomplete table alias assignment +JOIN table AS WHERE +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ keyword.other.dml.sql + +-------- + +USE AdventureWorks2012; +GO +DECLARE @MyTableVar table( + EmpID INT NOT NULL, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.table.sql meta.group.table-columns.sql +-- ^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql + OldVacationHours INT, + NewVacationHours INT, + ModifiedDate datetime, + Primary Key (EmpID)); +-- ^^^^^^^^^^^ meta.table.sql meta.group.table-columns.sql storage.modifier.sql +-- ^ meta.table.sql meta.group.table-columns.sql punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql - meta.group +UPDATE TOP (10) HumanResources.Employee +-- ^^^ keyword.other.dml +-- ^^^ keyword.other.dml +-- ^^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.parens.end +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +SET VacationHours = VacationHours * 1.25 +-- ^ keyword.operator.arithmetic +-- ^^^^ meta.number.float.decimal constant.numeric.value +OUTPUT INSERTED.BusinessEntityID, +--^^^^ storage.modifier.output +-- ^^^^^^^^^ meta.column-name constant.language.table +-- ^ meta.column-name constant.language.table punctuation.accessor.dot +-- ^^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence + DELETED.VacationHours, +-- ^^^^^^^^ meta.column-name constant.language.table +-- ^ meta.column-name constant.language.table punctuation.accessor.dot +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence + INSERTED.VacationHours, + INSERTED.ModifiedDate +INTO @MyTableVar; +--Display the result set of the table variable. +SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate +FROM @MyTableVar; +GO +--Display the result set of the table. +--Note that ModifiedDate reflects the value generated by an +--AFTER UPDATE trigger. +SELECT TOP 10 percent BusinessEntityID, VacationHours, ModifiedDate +-- ^^^ keyword.other.dml +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^^^^^^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^ meta.column-name +FROM HumanResources.Employee; +GO +---------------- +DECLARE @XmlDocumentHandle int +DECLARE @XmlDocument nvarchar(1000) +SET @XmlDocument = N' + + VINET + Paul Henriot + + + + + + + LILAS + Carlos Gonzlez + + + + +' +-- Create an internal representation of the XML document. +EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @XmlDocument +-- Execute a SELECT statement using OPENXML rowset provider. +SELECT * +FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath highlighting to the string +--^^ keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^ - meta.function-call +-- ^^^^^^^ meta.table-valued-function-name support.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^^^^^^^^^^ variable.other.readwrite + WITH (CustomerID varchar(10), +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.separator.sequence + ContactName varchar(20)) +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ - meta.group +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.section.group.end +EXEC sp_xml_removedocument @XmlDocumentHandle +-- <- keyword.control.flow.execute +-- ^ - meta.procedure-name +-- ^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ - meta.procedure-name +-- ^ variable.other.readwrite punctuation.definition.variable +-- ^^^^^^^^^^^^^^^^^ variable.other.readwrite - punctuation + +--Create an internal representation of the XML document. +EXEC sp_xml_preparedocument @idoc OUTPUT, @doc; +-- <- keyword.control.flow.execute +-- ^ - meta.procedure-name +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ - meta.procedure-name +-- ^ variable.other.readwrite punctuation.definition.variable +-- ^^^^ variable.other.readwrite.sql +-- ^ - variable +-- ^^^^^^ storage.modifier.output.tsql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ variable.other.readwrite.sql +-- ^ punctuation.terminator.statement.sql + +-- SELECT stmt using OPENXML rowset provider +SELECT * +FROM OPENXML (@idoc, '/ROOT/Customer/Order/OrderDetail',2) + WITH (OrderID int '../@OrderID', + CustomerID varchar(10) '../@CustomerID', + OrderDate datetime '../@OrderDate', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^^ storage.type +-- ^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ punctuation.separator.sequence + ProdID int '@ProductID', + Qty int '@Quantity'); +-- ^ meta.group.table-columns punctuation.section.group.end +-- ^ punctuation.terminator.statement - meta.group +----- +SELECT * +FROM table_name AS t1 + INNER JOIN (SELECT foo FROM bar) AS t2(id) ON t2.ID = t1.ID +-- ^^ keyword.operator.assignment.alias +-- ^^ meta.alias.table +-- ^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^ keyword.control.conditional +---- + +SELECT a.* + FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^^ meta.function-call meta.table-valued-function-name support.function +-- ^ punctuation.section.arguments.begin + 'C:\SAMPLES\Northwind.mdb'; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence + 'admin'; + 'password', + Customers) AS a; +-- ^ meta.function-call meta.group punctuation.section.arguments.end +-- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call +-- ^ meta.alias.table + +DECLARE @Data NVARCHAR(MAX) +-- ^^^^^^^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.begin +-- ^^^ constant.language.max.sql +-- ^ punctuation.section.group.end +SELECT @Data = ( + SELECT [CustomerID] as "@CustomerID", + [CustomerName], + [CustomerCategoryName], + [PrimaryContact], + [AlternateContact], + [PhoneNumber], + [FaxNumber], + [BuyingGroupName] AS '*', + [WebsiteURL] WebsiteLink, -- TODO: scope alias correctly when no explicit 'AS' + [DeliveryMethod] 'MethodOfDelivery' -- TODO: scope alias correctly when no explicit 'AS' + FROM [WideWorldImporters].[Website].[Customers] + WHERE CustomerID < 3 FOR XML PATH('Customer'), ROOT('Customers') +-- ^^^^^^^ keyword.other +-- ^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^ punctuation.separator.sequence +-- ^^^^ keyword.other +) +-- <- meta.group punctuation.section.group.end + +------------------- +CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +-- ^^^ keyword.other.ddl +-- ^^^^^^ keyword.other +-- ^^^^^^^^^^^^ keyword.other +-- ^^^^^ keyword.other +-- ^^^^^^^^^^^^^ entity.name.struct +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin + some_column ASC +-- ^^^^^^^^^^^ meta.group meta.column-name +-- ^^^ meta.group keyword.other.order +) +-- <- meta.group punctuation.section.group.end +--^ - meta.group +; +WITH cols +--^^ keyword.other.dml +-- ^^^^ meta.cte-table-name +AS +-- <- keyword.operator.assignment.cte +( + SELECT table_name, column_name, + ROW_NUMBER() OVER(ORDER BY table_name, column_name) AS sequence, + COUNT(*) OVER() AS total_columns + FROM [INFORMATION_SCHEMA].columns +) +SELECT table_name, column_name, total_columns +FROM cols +ORDER BY sequence + +set @test += 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test -= 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test *= 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test /= 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test %= 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test ^= 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test |= 2 +--^ keyword.other.dml +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value + +--------------- +CREATE PROCEDURE dbo.RetrievePersonAddress + @city_name NVARCHAR(30), + @postal_code NVARCHAR(15) +AS +SELECT * FROM Person.Address +WHERE City = @city_name AND PostalCode = @postal_code +OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) ); +-- ^^^ keyword.other.dml +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator.comparison +-- ^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^ variable.other.readwrite +-- ^^^^^^^ keyword.other +-- ^ punctuation.section.group.end +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement +GO + +SELECT * FROM Person.Address +WHERE City = @city_name AND PostalCode = @postal_code +OPTION (OPTIMIZE FOR UNKNOWN); +--^^^^ keyword.other.dml - meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + + +CREATE NONCLUSTERED INDEX IX_Address_PostalCode +ON Person.Address (PostalCode) +-- <- keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID) +-- ^^^^ keyword.other - meta.function-call - support.function +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +WHERE CountryCode = 'FR' + + /**/ +--^^^^ comment.block - comment.block.documentation +--^^ punctuation.definition.comment.begin +-- ^^ punctuation.definition.comment.end + + /***/ +--^^^ comment.block.documentation punctuation.definition.comment.begin +-- ^^ comment.block.documentation punctuation.definition.comment.end + + /****/ +--^^^^ comment.block.documentation punctuation.definition.comment.begin +-- ^^ comment.block.documentation punctuation.definition.comment.end + + /*** + *** +-- ^ comment.block.documentation punctuation.definition.comment + ^^ - punctuation + ***/ +-- ^^^^ comment.block.documentation punctuation.definition.comment.end + +SELECT FLOOR(hours / 24) as days, hours%24 as hours +-- ^ keyword.operator.arithmetic +FROM timings + +-- Temporal table +CREATE TABLE Department +( + DepartmentNumber CHAR(10) NOT NULL PRIMARY KEY CLUSTERED, + DepartmentName VARCHAR(50) NOT NULL, + ManagerID INT NULL, + ParentDepartmentNumber CHAR(10) NULL, + SysStartTime DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL, +-- ^^^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^ storage.type +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^ punctuation.separator.sequence + SysEndTime DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL, +-- ^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^ storage.type +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^ punctuation.separator.sequence + PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime) +-- ^^^^^^^^^^^^^^^^^^^^^^ storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.column-name - variable.other.member.declaration +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^ meta.column-name - variable.other.member.declaration +-- ^ punctuation.section.group.end +) +WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.Department_History, DATA_CONSISTENCY_CHECK = ON)); +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create +--^^ keyword.other.dml +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^ constant.language.boolean +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.boolean +-- ^ punctuation.section.group.end +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE TABLE Customers ( + CustName NVARCHAR(60) + ENCRYPTED WITH ( +-- ^^^^^^^^^^^^^^ storage.modifier + COLUMN_ENCRYPTION_KEY = MyCEK, +-- ^^^^^^^^^^^^^^^^^^^^^ constant.language.with + ENCRYPTION_TYPE = RANDOMIZED, +-- ^^^^^^^^^^^^^^^ constant.language.with + ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256' +-- ^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single + ), +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence + SSN VARCHAR(11) COLLATE Latin1_General_BIN2 +-- ^^^ meta.statement.create meta.group.table-columns meta.column-name variable.other.member.declaration +-- ^^^^^^^^^^^ storage.type +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^ support.constant + ENCRYPTED WITH ( +-- ^^^^^^^^^^^^^^ storage.modifier + COLUMN_ENCRYPTION_KEY = MyCEK, + ENCRYPTION_TYPE = DETERMINISTIC , + ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256' + ), + Age INT NULL +); + +ALTER TABLE inventory +ADD CONSTRAINT fk_inv_product_id +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +--^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^^^^^^^^ meta.constraint-name + FOREIGN KEY (product_id) +-- ^^^^^^^^^^^ meta.statement.alter storage.modifier +-- ^ meta.statement.alter meta.group.table-columns punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name + REFERENCES products (product_id) +-- ^^^^^^^^^^ meta.statement.alter storage.modifier +-- ^^^^^^^^ meta.statement.alter meta.table-name +-- ^ meta.statement.alter meta.group.table-columns punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end + ON DELETE CASCADE; +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter storage.modifier +-- ^ punctuation.terminator.statement + +BEGIN TRY +-- <- keyword.control.exception +-- ^^^^^^ keyword.control.exception + -- Generate divide-by-zero error. + SELECT 1/0; +END TRY +-- <- keyword.control.exception +-- ^^^^ keyword.control.exception +BEGIN CATCH +-- <- keyword.control.exception +-- ^^^^^^^^ keyword.control.exception + -- Execute error retrieval routine. + EXECUTE usp_GetErrorInfo; +END CATCH; +-- <- keyword.control.exception +-- ^^^^^^ keyword.control.exception + +BEGIN +-- <- keyword.control.flow.begin + WAITFOR DELAY '02:00'; +-- ^^^^^^^ keyword.control.flow.waitfor +-- ^^^^^ storage.type +-- ^^^^^^^ meta.string string.quoted.single +-- ^ punctuation.terminator.statement + EXECUTE sp_helpdb; +-- ^^^^^^^ keyword.control.flow.execute +-- ^^^^^^^^^ meta.procedure-name +END; + +BEGIN +-- <- keyword.control.flow.begin + WAITFOR TIME '22:20'; +-- ^^^^^^^ keyword.control.flow.waitfor +-- ^^^^ storage.type +-- ^^^^^^^ meta.string string.quoted.single +-- ^ punctuation.terminator.statement + EXECUTE sp_helpdb; +-- ^^^^^^^ keyword.control.flow.execute +-- ^^^^^^^^^ meta.procedure-name +END; + +IF DATENAME(weekday, GETDATE()) IN (N'Saturday', N'Sunday') +-- <- keyword.control.conditional +-- ^^^^^^^^ meta.function-call support.function +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.group +-- ^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group + SELECT 'Weekend'; +-- ^^^^^^ keyword.other.dml +ELSE +-- <- keyword.control.conditional + SELECT 'Weekday'; +-- ^^^^^^ keyword.other.dml + +WHILE TRUE +-- <- keyword.control.loop + BREAK +-- ^^^^^ keyword.control.flow.break + CONTINUE +-- ^^^^^^^^ keyword.control.flow.continue +END +-- <- keyword.control.flow.end + + CURRENT_USER SESSION_USER SYSTEM_USER USER +-- ^^^^^^^^^^^^ support.function.user.sql +-- ^^^^^^^^^^^^ support.function.user.sql +-- ^^^^^^^^^^^ support.function.user.sql +-- ^^^^ support.function.user.sql + +GRANT ALL +-- ^^ keyword.other.authorization.sql +-- ^^^ constant.language.sql + +GRANT ALL PRIVILEGES +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^ constant.language.sql + +GRANT CREATE TABLE TO MelanieK; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +GRANT DROP TABLE, ALTER COLUMN TO me +-- ^^ keyword.other.authorization.sql +-- ^ punctuation.separator.sequence.sql +-- ^^ keyword.context.sql + +GRANT CREATE VIEW TO CarmineEs WITH GRANT OPTION; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^ meta.username.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^ constant.language.with.tsql +-- ^^^^^^ constant.language.with.tsql + +GRANT CONTROL ON DATABASE::AdventureWorks2012 TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^ constant.language.tsql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^^^^^^^^^^^^^^ meta.database-name.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql + +GRANT CONTROL ON ROLE::Admin TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^ constant.language.tsql +-- ^^ keyword.context.resource.tsql +-- ^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^ meta.username.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql + +GRANT INSERT ON dbo.some_table TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^^^^^^^ string.quoted.tsql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +GRANT UPDATE ON dbo.some_table (some_id, [some_field]) TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^^^^^^^ string.quoted.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.section.group.end.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +GRANT SELECT ON schema::some_schema TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^^^^^^^ meta.database-name.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +GRANT SHOWPLAN TO AuditMonitor; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +grant view server state to somebody; +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +grant execute on some_schema.some_procedure to somebody; +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +ALTER ROLE buyers WITH NAME = purchasing; +--^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^^^ string.unquoted.tsql +-- ^ punctuation.terminator.statement.sql + +ALTER ROLE Sales ADD MEMBER Barry; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql +ALTER ROLE Sales DROP MEMBER Barry; +--^^^^^^^^^^^^^^^ meta.statement.alter.sql +--^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^ punctuation.terminator.statement.sql + +CREATE USER "some-name-here" FROM external provider with OBJECT_ID="ba5615a6-f2ca-4517-97d1-36fc8a595fc9"; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ entity.name +-- ^^^^^^^^^^^^^^^^^^^^^^ constant.language.tsql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.tsql +ALTER ROLE "db_datareader" ADD MEMBER "some-name-here"; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.other-name.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql +ALTER USER [yourUser] WITH DEFAULT_SCHEMA = myschema; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.other-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^ string.unquoted.tsql +-- ^ punctuation.terminator.statement.sql + +create user user_name_in_sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ entity.name + with sid = 0x67453e129be8d312a456426614174000, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.dml.sql +-- ^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.number.integer.hexadecimal.tsql +-- ^ punctuation.separator.sequence.sql + type = E; +--^^^^^^^^ meta.statement.create.sql +-- ^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^ string.unquoted.tsql +-- ^ punctuation.terminator.statement.sql + +DROP USER iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ storage.type.sql - meta.username +-- ^^^^ meta.username.sql + +DROP USER IF EXISTS iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ storage.type.sql - meta.username +-- ^^ keyword.control.conditional.if.sql - meta.username +-- ^^^^^^ keyword.operator.logical.sql - meta.username +-- ^^^^ meta.username.sql + +DROP USER IF EXISTS "some-name-here"; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^ storage.type.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql - meta.username +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.terminator.statement.sql + +-- https://stackoverflow.com/a/14860368/4473405 +SELECT a, + b, + COUNT(*) OVER (ORDER BY a + ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Rows], +-- ^^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^ keyword.other.sql + COUNT(*) OVER (ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Range], +-- ^^^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^ keyword.other.sql + COUNT(*) OVER() AS [Over()] + FROM t; + +SELECT STRING_AGG (CONVERT(NVARCHAR(max),FirstName), CHAR(13)) AS csv +-- ^^^^^^^^ storage.type.sql +-- ^ +-- ^^^ constant.language.max.sql +FROM Person.Person; + +SELECT STRING_AGG(CONVERT(NVARCHAR(max), ISNULL(FirstName,'N/A')), ',') AS csv +FROM Person.Person; + +SELECT TOP 10 City, STRING_AGG(CONVERT(NVARCHAR(max), EmailAddress), ';') WITHIN GROUP (ORDER BY EmailAddress ASC) AS Emails +-- ^^^^^^^^^^^^ keyword.other.tsql +-- ^ meta.group.sql punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.group.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.sql meta.column-name.sql +-- ^^^ meta.group.sql keyword.other.order.sql +-- ^ meta.group.sql punctuation.section.group.end.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^ meta.alias.column.sql +FROM Person.BusinessEntityAddress AS BEA +INNER JOIN Person.Address AS A ON BEA.AddressID = A.AddressID +INNER JOIN Person.EmailAddress AS EA ON BEA.BusinessEntityID = EA.BusinessEntityID +GROUP BY City; + +DECLARE @g geography; +SET @g = geography::Point(47.65100, -122.34900, 4326) +-- ^^^^^^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^ meta.function-call.sql support.function.sql +SELECT @g.ToString(); +-- ^^^ keyword.other.dml.sql +-- ^ variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^ variable.other.readwrite.sql +-- ^ punctuation.accessor.dot.tsql +-- ^^^^^^^^ meta.function-call.sql support.function.sql +-- ^ meta.function-call.sql meta.group.sql punctuation.section.arguments.begin.sql +-- ^ meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql +-- ^ punctuation.terminator.statement.sql + +DECLARE @FromTimeUTC DATETIME2, @ToTimeUTC DATETIME2 +-- ^^^^ keyword.declaration.variable.sql +-- ^^^^^^^^^^^^ variable.other.readwrite.declaration.tsql +-- ^^^^^^^^^ storage.type.sql +-- ^ punctuation.separator.sequence.tsql +-- ^^^^^^^^^^ variable.other.readwrite.declaration.tsql +-- ^^^^^^^^^ storage.type.sql + +CREATE CLUSTERED INDEX ix_some_table_some_field_another_field ON dbo.some_table (some_field, another_field); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^ punctuation.terminator.statement.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.index.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.index.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +SET @local_datetime = cast(t.created_date AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time' as time) +-- ^^^^^^^^^^^^ storage.modifier.tsql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^^^^^^^^^ storage.modifier.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^ keyword.operator.assignment.tsql +-- ^^^^ storage.type.sql + +DROP USER IF EXISTS [foo] +CREATE USER [foo] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[bar] +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^ storage.modifier.tsql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^ string +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +GO +-- <- keyword.control.flow.go.tsql - meta.statement.create + +GRANT CREATE SEQUENCE ON SCHEMA::Test TO [AdventureWorks\Larry]; +CREATE SEQUENCE Test.DecSeq + AS decimal(3,0) + START WITH 125 + INCREMENT BY 25 + MINVALUE 100 + MAXVALUE 200 + CYCLE + CACHE 3; +-- ^^^^^ meta.statement.create keyword.other.ddl + +SELECT NEXT VALUE FOR Test.DecSeq; +-- ^^^ keyword.other.dml +-- ^^^^^^^^^^ keyword.other +-- ^^^ keyword.other + +set transaction isolation level read committed; +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql constant.language.switch.tsql +-- ^^^^^^^^^^^^^^ meta.statement.set.sql constant.language.tsql +-- ^ punctuation.terminator.statement.sql - meta.statement.set + + +declare @foo table (a int, b int) +declare @bar table (a int, b int) +declare @inserted table (action nvarchar(10), a int, b int) + +insert into @foo values + (1,2), + (3,4) + +insert into @bar values + (1,22), + (2,44) + +merge @foo foo +using @bar bar + on foo.a = bar.a +when matched then + update set foo.b = bar.b +when not matched then + insert (a,b) values (bar.a, bar.b) +output $action, inserted.* +into @inserted +; + +select * from @foo +select * from @inserted + +merge into @foo foo +-- ^^^^^^^ keyword.other.tsql +-- ^^^^ meta.table-name.sql variable.other.readwrite.sql +-- ^^^ meta.alias.table.sql +using (values ( +-- ^^ keyword.context.resource.tsql +-- ^ meta.group.sql punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml +-- ^ punctuation.section.group.begin.sql + 1, + 22 + )) AS +-- ^ meta.group.sql meta.group.sql punctuation.section.group.end.sql +-- ^ meta.group.sql punctuation.section.group.end.sql - meta.group meta.group +-- ^^ keyword.operator.assignment.alias.sql - meta.group + bar ( +-- ^^^ meta.alias.table.sql +-- ^ meta.group.sql punctuation.section.group.begin.sql + a, +-- ^ meta.group.sql meta.column-name.sql + b + ) + on foo.a = bar.a +when matched then + update set foo.b = bar.b +when not matched then + insert (a,b) values (bar.a, bar.b) + +output $action, inserted.* +-- ^^^ storage.modifier.output.tsql +-- ^^^^^^^ variable.language.tsql +into @inserted +; + +MERGE INTO some_schema.some_table WITH (holdlock) AS target +-- ^^^^^^^ keyword.other.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^ meta.group.sql punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.group.sql constant.language.with.tsql +-- ^ meta.group.sql punctuation.section.group.end.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^ meta.alias.table.sql +USING some_schema.another_table AS source +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^ meta.alias.table.sql +ON source.some_id = target.some_id +-- <- keyword.control.conditional.sql +when matched then + update set target.b = source.b +when not matched then + insert (a,b,c) values (source.a, source.b, default); +-- ^^^^^^^ meta.group.sql variable.language.tsql + +DECLARE @deadlock_var NCHAR(3); +SET @deadlock_var = N'LOW'; + +SET DEADLOCK_PRIORITY @deadlock_var; +-- ^^^^^^^^^^^^^^^^^ constant.language.switch.tsql +-- ^ punctuation.definition.variable.sql +-- ^^^^^^^^^^^^ variable.other.readwrite.sql +-- ^ punctuation.terminator.statement.sql +SET DEADLOCK_PRIORITY NORMAL; +-- ^^^^^^^^^^^^^^^^^ constant.language.switch.tsql +-- ^^^^^^ constant.language.tsql +SET DEADLOCK_PRIORITY -10; +-- ^^^^^^^^^^^^^^^^^ constant.language.switch.tsql +-- ^ keyword.operator.arithmetic.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + +INSERT INTO some_schema.some_table + (id, some_field) +SELECT main.id, other.another_field +FROM @table_variable AS main +CROSS JOIN some_func(@param) AS other +-- ^^^^^^^ keyword.other.dml.sql + +DROP TABLE IF EXISTS #SampleTempTable; +GO +CREATE TABLE #SampleTempTable (id INT, message nvarchar(50)); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.table.sql entity.name.struct.table.sql +-- ^ punctuation.definition.variable.tsql +INSERT INTO #SampleTempTable VALUES (null, 'hello'); +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ meta.table-name.sql punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^^ meta.table-name.sql - punctuation +INSERT INTO #SampleTempTable VALUES (10, null); +INSERT INTO #SampleTempTable VALUES (17, 'abc'); +INSERT INTO #SampleTempTable VALUES (17, 'yes'); +INSERT INTO #SampleTempTable VALUES (null, null); +GO + +SELECT * FROM #SampleTempTable WHERE id IS DISTINCT FROM 17; +DROP TABLE IF EXISTS #SampleTempTable; +GO + +ALTER TABLE a.b WITH CHECK +-- ^^^^^^^^^^ meta.statement.alter.sql keyword.other.ddl.tsql + ADD CONSTRAINT fk_b_c +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql + FOREIGN KEY (some_id) REFERENCES a.c (some_id); +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^ meta.group.table-columns.sql + + +SELECT * FROM table FOR SYSTEM_TIME AS OF 131512 alias +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^ keyword.operator.logical +-- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ meta.alias.table.sql + +SELECT * FROM table FOR SYSTEM_TIME CONTAINED IN (131512, 231) alias +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.table.sql +-- + +CREATE TABLE a.b ( + id int + CONSTRAINT pk_b PRIMARY KEY, + external_id varchar(256) NOT NULL + CONSTRAINT uq_b_external_id UNIQUE, +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^^ meta.constraint-name.sql +-- ^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql + name varchar(512) NOT NULL +-- ^^^^ meta.column-name.sql variable.other.member.declaration.sql +); +-- <- meta.statement.create.sql meta.table.sql meta.group.table-columns.sql punctuation.section.group.end.sql + +ALTER TABLE schema.table + ADD sequence smallint NOT NULL; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^^ storage.type.sql + +ALTER TABLE schema.table + ADD constraint_not bit; +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.column-name.sql +-- ^^^ storage.type.sql + +MERGE a.b WITH (HOLDLOCK, UPDLOCK) lock +USING (SELECT @name AS name) job + ON lock.name = job.name +WHEN MATCHED AND (acquired IS NULL OR @now > timeout) THEN +-- ^^^^^^^^^ keyword.control.conditional.case.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^ keyword.other.tsql + UPDATE + SET acquired = @now, timeout = @timeout +WHEN NOT MATCHED AND @insert_if_missing = 1 THEN +-- ^^^^^^^^^^^^^ keyword.control.conditional.case.sql +-- ^^^ keyword.operator.logical.sql +-- ^ variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^^^^^^^^^^^^^^^^^ variable.other.readwrite.sql +-- ^ keyword.operator.comparison.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.tsql + INSERT (name, acquired, timeout) +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + VALUES (@name, @now, @timeout); +-- ^^^^^^ keyword.other.dml +-- ^ meta.group.sql punctuation.section.group.begin.sql + +WITH XMLNAMESPACES ('uri' as ns1) +SELECT ProductID as 'ns1:ProductID', + Name as 'ns1:Name', + Color as 'ns1:Color' +FROM Production.Product +WHERE ProductID IN (316, 317) +FOR XML RAW ('ns1:Prod'), ELEMENTS; + +WITH XMLNAMESPACES ('uri1' as ns1, +-- ^ keyword.other.dml + 'uri2' as ns2, + DEFAULT 'uri2') +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^^^^^^^ variable.language +-- ^^^^^^ meta.string string.quoted.single +-- ^ punctuation.section.group.end +-- ^ - meta.group.table-columns +SELECT ProductID, + Name, + Color +FROM Production.Product +WHERE ProductID IN (316, 317) +FOR XML RAW ('ns1:Product'), ROOT('ns2:root'), ELEMENTS; + +SELECT e.BusinessEntityID, e.NationalIDNumber, e.OrganizationNode, e.JobTitle, + X.Y.value('(BankName)[1]', 'VARCHAR(20)') as BankName, +-- ^^^^^^^^^ meta.function-call variable.function +-- ^ punctuation.accessor.dot +-- ^ punctuation.accessor.dot + X.Y.value('(AnnualRevenue)[1]', 'VARCHAR(20)') as AnnualRevenue, + X.Y.value('(BusinessType)[1]', 'VARCHAR(256)') as BusinessType, + X.Y.value('(Specialty)[1]', 'VARCHAR(128)') as Specialty +FROM HumanResources.Employee e +CROSS APPLY e.emp_xml.nodes('EmployeeDetails/StoreDetail/Store') as X(Y) +