Grammar diagrams YCQL

alter_table

alter_table ::= ALTER TABLE table_name 
                { ADD { column_name column_type } [ , ... ]
                  | DROP { column_name [ , ... ] }
                  | RENAME { column_name TO column_name } [ , ... ]
                  | WITH { property_name = property_literal } 
                    [ AND ... ] } [ ... ]

ALTERTABLEtable_nameADD,column_namecolumn_typeDROP,column_nameRENAME,column_nameTOcolumn_nameWITHANDproperty_name=property_literal

column_type

column_type ::= '<type>'

<type>

create_index

create_index ::= CREATE [ UNIQUE ] INDEX [ IF NOT EXISTS ] index_name 
                 ON  table_name ( partition_key_columns , 
                 [ clustering_key_columns ] )  [ covering_columns ] 
                 [ index_properties ] [ WHERE index_predicate ]

CREATEUNIQUEINDEXIFNOTEXISTSindex_nameONtable_name(partition_key_columns,clustering_key_columns)covering_columnsindex_propertiesWHEREindex_predicate

partition_key_columns

partition_key_columns ::= index_column | ( index_column [ , ... ] )

index_column(,index_column)

clustering_key_columns

clustering_key_columns ::= index_column [ , ... ]

,index_column

index_properties

index_properties ::= WITH 
                     { property_name = property_literal
                       | CLUSTERING ORDER BY ( 
                         { index_column [ ASC | DESC ] } [ , ... ] ) } 
                     [ AND ... ]

WITHANDproperty_name=property_literalCLUSTERINGORDERBY(,index_columnASCDESC)

index_column

index_column ::= column_name | jsonb_attribute

column_namejsonb_attribute

jsonb_attribute

jsonb_attribute ::= column_name [ -> ''attribute_name'' [ ... ] ] ->> 
                    ''attribute_name''

column_name->'attribute_name'->>'attribute_name'

covering_columns

covering_columns ::= { COVERING | INCLUDE } ( column_name [ , ... ] )

COVERINGINCLUDE(,column_name)

index_predicate

index_predicate ::= where_expression

where_expression

create_keyspace

create_keyspace ::= CREATE { KEYSPACE | SCHEMA } [ IF NOT EXISTS ] 
                    keyspace_name keyspace_properties

CREATEKEYSPACESCHEMAIFNOTEXISTSkeyspace_namekeyspace_properties

keyspace_properties

keyspace_properties ::= [ WITH REPLICATION = { keyspace_property 
                          [ , ... ] } ] 
                        [ AND DURABLE_WRITES = { 'true' | 'false' } ]

WITHREPLICATION={,keyspace_property}ANDDURABLE_WRITES=truefalse

keyspace_property

keyspace_property ::= property_name = property_literal

property_name=property_literal

create_table

create_table ::= CREATE TABLE [ IF NOT EXISTS ] table_name ( 
                 table_schema ) [ table_properties ]

CREATETABLEIFNOTEXISTStable_name(table_schema)table_properties

table_schema

table_schema ::= { column_name column_type 
                   { PRIMARY KEY | STATIC } [ ... ]
                   | PRIMARY KEY ( ( column_name [ , ... ] ) 
                     [ , column_name [ ... ] ] ) } [ , ... ]

,column_namecolumn_typePRIMARYKEYSTATICPRIMARYKEY((,column_name),column_name)

table_properties

table_properties ::= WITH 
                     { property_name = property_literal
                       | CLUSTERING ORDER BY ( 
                         { column_name [ ASC | DESC ] } [ , ... ] )
                       | COMPACT STORAGE } [ AND ... ]

WITHANDproperty_name=property_literalCLUSTERINGORDERBY(,column_nameASCDESC)COMPACTSTORAGE

create_type

create_type ::= CREATE TYPE [ IF NOT EXISTS ] type_name ( 
                { field_name field_type } [ , ... ] )

CREATETYPEIFNOTEXISTStype_name(,field_namefield_type)

field_type

field_type ::= '<type>'

<type>

drop_keyspace

drop_keyspace ::= DROP { KEYSPACE | SCHEMA } [ IF EXISTS ] 
                  keyspace_name

DROPKEYSPACESCHEMAIFEXISTSkeyspace_name

drop_table

drop_table ::= DROP TABLE [ IF EXISTS ] table_name

DROPTABLEIFEXISTStable_name

drop_type

drop_type ::= DROP TYPE [ IF EXISTS ] type_name

DROPTYPEIFEXISTStype_name

use_keyspace

use_keyspace ::= USE keyspace_name

USEkeyspace_name

delete

delete ::= DELETE FROM table_name 
               [ USING TIMESTAMP timestamp_expression ] WHERE 
               where_expression [ IF { [ NOT ] EXISTS | if_expression } ] 
               [ RETURNS STATUS AS ROW ]

DELETEFROMtable_nameUSINGTIMESTAMPtimestamp_expressionWHEREwhere_expressionIFNOTEXISTSif_expressionRETURNS STATUS AS ROW

where_expression

where_expression ::= { column_name { < | <=
                                     | = | >=
                                     | > | IN
                                     | NOT IN } expression } 
                     [ AND ... ]

ANDcolumn_name<<==>=>INNOT INexpression

if_expression

if_expression ::= { column_name { < | <= | = | >= | > | IN | NOT IN } 
                  expression } [ AND ... ]

ANDcolumn_name<<==>=>INNOT INexpression

insert

insert ::= INSERT INTO table_name ( column_name [ , ... ] ) VALUES ( 
           expression [ , ... ] )  
           [ IF { [ NOT ] EXISTS | if_expression } ] 
           [ USING using_expression ] 
           [ RETURNS STATUS AS ROW ]

INSERTINTOtable_name(,column_name)VALUES(,expression)IFNOTEXISTSif_expressionUSINGusing_expressionRETURNS STATUS AS ROW

using_expression

using_expression ::= ttl_or_timestamp_expression [ AND ... ]

ANDttl_or_timestamp_expression

ttl_or_timestamp_expression

ttl_or_timestamp_expression ::= TTL ttl_expression
                                | TIMESTAMP timestamp_expression

TTLttl_expressionTIMESTAMPtimestamp_expression

expression

expression ::= '<expression>'

<expression>

select

select ::= SELECT [ DISTINCT ] { * | column_name [ , ... ] } FROM 
           table_name  [ WHERE where_expression [ ALLOW FILTERING ] ]  
           [ IF if_expression ]  [ ORDER BY order_expression ]  
           [ LIMIT limit_expression ] [ OFFSET offset_expression ]

SELECTDISTINCT*,column_nameFROMtable_nameWHEREwhere_expressionALLOW FILTERINGIFif_expressionORDER BYorder_expressionLIMITlimit_expressionOFFSEToffset_expression

order_expression

order_expression ::= ( { column_name [ ASC | DESC ] } [ , ... ] )

(,column_nameASCDESC)

update

update ::= UPDATE table_name [ USING using_expression ] SET assignment 
               [ , ... ]  WHERE where_expression 
               [ IF { [ NOT ] EXISTS | if_expression } ] 
               [ RETURNS STATUS AS ROW ]

UPDATEtable_nameUSINGusing_expressionSET,assignmentWHEREwhere_expressionIFNOTEXISTSif_expressionRETURNS STATUS AS ROW

transaction_block

transaction_block ::= BEGIN TRANSACTION  
                      { { insert | update | delete } ; } [ ... ]  END 
                      TRANSACTION ;

BEGINTRANSACTIONinsertupdatedelete;ENDTRANSACTION;

truncate

truncate ::= TRUNCATE [ TABLE ] table_name

TRUNCATETABLEtable_name

assignment

assignment ::= column_name = expression

column_name=expression

ttl_expression

ttl_expression ::= '<Integer Literal>'

<Integer Literal>

timestamp_expression

timestamp_expression ::= '<Integer Literal>'

<Integer Literal>

limit_expression

limit_expression ::= '<Integer Literal>'

<Integer Literal>

offset_expression

offset_expression ::= '<Integer Literal>'

<Integer Literal>

keyspace_name

keyspace_name ::= '<Text Literal>'

<Text Literal>

property_name

property_name ::= '<Text Literal>'

<Text Literal>

property_literal

property_literal ::= '<Text Literal>'

<Text Literal>

table_name

table_name ::= [ keyspace_name . ] '<Text Literal>'

keyspace_name.<Text Literal>

index_name

index_name ::= '<Text Literal>'

<Text Literal>

column_name

column_name ::= '<Text Literal>'

<Text Literal>

type_name

type_name ::= [ keyspace_name . ] '<Text Literal>'

keyspace_name.<Text Literal>

field_name

field_name ::= '<Text Literal>'

<Text Literal>

alter_role

alter_role ::= ALTER ROLE role_name WITH role_property [ AND ... ]

ALTERROLErole_nameWITHANDrole_property

create_role

create_role ::= CREATE ROLE [ IF NOT EXISTS ] role_name 
                [ WITH role_property [ AND ... ] ]

CREATEROLEIFNOTEXISTSrole_nameWITHANDrole_property

role_property

role_property ::= PASSWORD = '<Text Literal>'
                  | LOGIN = '<Boolean Literal>'
                  | SUPERUSER = '<Boolean Literal>'

PASSWORD=<Text Literal>LOGIN=<Boolean Literal>SUPERUSER=<Boolean Literal>

drop_role

drop_role ::= DROP ROLE [ IF EXISTS ] role_name

DROPROLEIFEXISTSrole_name

grant_role

grant_role ::= GRANT role_name TO role_name

GRANTrole_nameTOrole_name

revoke_role

revoke_role ::= REVOKE role_name FROM role_name

REVOKErole_nameFROMrole_name

grant_permission

grant_permission ::= GRANT { all_permissions | permission } ON 
                     resource TO role_name

GRANTall_permissionspermissionONresourceTOrole_name

revoke_permission

revoke_permission ::= REVOKE { all_permissions | permission } ON 
                      resource FROM role_name

REVOKEall_permissionspermissionONresourceFROMrole_name

all_permissions

all_permissions ::= ALL [ PERMISSIONS ]

ALLPERMISSIONS

role_name

role_name ::= '<Text Literal>'

<Text Literal>

permission

permission ::= { CREATE
                 | ALTER
                 | DROP
                 | SELECT
                 | MODIFY
                 | AUTHORIZE
                 | DESCRIBE
                 | EXECUTE } [ PERMISSION ]

CREATEALTERDROPSELECTMODIFYAUTHORIZEDESCRIBEEXECUTEPERMISSION

resource

resource ::= ALL { KEYSPACES | ROLES }
             | KEYSPACE keyspace_name
             | [ TABLE ] table_name
             | ROLE role_name

ALLKEYSPACESROLESKEYSPACEkeyspace_nameTABLEtable_nameROLErole_name

alter_keyspace

alter_keyspace ::= ALTER { KEYSPACE | SCHEMA } keyspae_name 
                   keyspace_properties

ALTERKEYSPACESCHEMAkeyspae_namekeyspace_properties

explain

explain ::= EXPLAIN { select | update | insert | delete }

EXPLAINselectupdateinsertdelete