blob: b61df0664032851a8bee7694d8c5a7230c0e5b84 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance. Linear scalability and proven fault-tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data. Cassandra's support for replicating across multiple datacenters is best-in-class, providing lower latency for your users and the peace of mind of knowing that you can survive regional outages.
">
<meta name="keywords" content="cassandra, apache, apache cassandra, distributed storage, key value store, scalability, bigtable, dynamo" />
<meta name="robots" content="index,follow" />
<meta name="language" content="en" />
<title>Documentation</title>
<link rel="canonical" href="http://cassandra.apache.org/doc/4.0/cql/definitions.html">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="./../../../css/style.css">
<link rel="stylesheet" href="./../../../css/sphinx.css">
<link rel="top" title="Apache Cassandra Documentation v4.0" href="../index.html"/> <link rel="up" title="The Cassandra Query Language (CQL)" href="index.html"/> <link rel="next" title="Data Types" href="types.html"/> <link rel="prev" title="The Cassandra Query Language (CQL)" href="index.html"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<link type="application/atom+xml" rel="alternate" href="http://cassandra.apache.org/feed.xml" title="Apache Cassandra Website" />
</head>
<body>
<!-- breadcrumbs -->
<div class="topnav">
<div class="container breadcrumb-container">
<ul class="breadcrumb">
<li>
<div class="dropdown">
<img class="asf-logo" src="./../../../img/asf_feather.png" />
<a data-toggle="dropdown" href="#">Apache Software Foundation <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li><a href="http://www.apache.org">Apache Homepage</a></li>
<li><a href="http://www.apache.org/licenses/">License</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="http://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li><a href="http://www.apache.org/security/">Security</a></li>
</ul>
</div>
</li>
<li><a href="./../../../">Apache Cassandra</a></li>
<li><a href="./../../../doc">Documentation</a></li>
<li><a href="./">The Cassandra Query Language (CQL)</a></li>
<li>Definitions</li>
</ul>
</div>
<!-- navbar -->
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#cassandra-menu" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./../../../"><img src="./../../../img/cassandra_logo.png" alt="Apache Cassandra logo" /></a>
</div><!-- /.navbar-header -->
<div id="cassandra-menu" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="./../../../">Home</a></li>
<li><a href="./../../../download/">Download</a></li>
<li><a href="./../../../doc/">Documentation</a></li>
<li><a href="./../../../community/">Community</a></li>
<li>
<a href="./../../../blog/">Blog</a>
</li>
</ul>
</div><!-- /#cassandra-menu -->
</div>
</nav><!-- /.navbar -->
</div><!-- /.topnav -->
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="doc-navigation">
<div class="doc-menu" role="navigation">
<div class="navbar-header">
<button type="button" class="pull-left navbar-toggle" data-toggle="collapse" data-target=".sidebar-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse sidebar-navbar-collapse">
<form id="doc-search-form" class="navbar-form" action="../search.html" method="get" role="search">
<div class="form-group">
<input type="text" size="30" class="form-control input-sm" name="q" placeholder="Search docs">
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</div>
</form>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../getting_started/index.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../architecture/index.html">Architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data_modeling/index.html">Data Modeling</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">The Cassandra Query Language (CQL)</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">Definitions</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#conventions">Conventions</a></li>
<li class="toctree-l3"><a class="reference internal" href="#identifiers">Identifiers and keywords</a></li>
<li class="toctree-l3"><a class="reference internal" href="#constants">Constants</a></li>
<li class="toctree-l3"><a class="reference internal" href="#terms">Terms</a></li>
<li class="toctree-l3"><a class="reference internal" href="#comments">Comments</a></li>
<li class="toctree-l3"><a class="reference internal" href="#statements">Statements</a></li>
<li class="toctree-l3"><a class="reference internal" href="#prepared-statements">Prepared Statements</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="types.html">Data Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="ddl.html">Data Definition</a></li>
<li class="toctree-l2"><a class="reference internal" href="dml.html">Data Manipulation</a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html">Secondary Indexes</a></li>
<li class="toctree-l2"><a class="reference internal" href="mvs.html">Materialized Views</a></li>
<li class="toctree-l2"><a class="reference internal" href="security.html">Security</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="operators.html">Arithmetic Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="json.html">JSON Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="triggers.html">Triggers</a></li>
<li class="toctree-l2"><a class="reference internal" href="appendices.html">Appendices</a></li>
<li class="toctree-l2"><a class="reference internal" href="changes.html">Changes</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../configuration/index.html">Configuring Cassandra</a></li>
<li class="toctree-l1"><a class="reference internal" href="../operating/index.html">Operating Cassandra</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Cassandra Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../troubleshooting/index.html">Troubleshooting</a></li>
<li class="toctree-l1"><a class="reference internal" href="../development/index.html">Contributing to Cassandra</a></li>
<li class="toctree-l1"><a class="reference internal" href="../faq/index.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../plugins/index.html">Third-Party Plugins</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bugs.html">Reporting Bugs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contactus.html">Contact us</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="col-md-8">
<div class="content doc-content">
<div class="content-container">
<div class="section" id="definitions">
<h1>Definitions<a class="headerlink" href="#definitions" title="Permalink to this headline"></a></h1>
<div class="section" id="conventions">
<span id="id1"></span><h2>Conventions<a class="headerlink" href="#conventions" title="Permalink to this headline"></a></h2>
<p>To aid in specifying the CQL syntax, we will use the following conventions in this document:</p>
<ul class="simple">
<li>Language rules will be given in an informal <a class="reference external" href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form#Variants">BNF variant</a> notation. In particular, we’ll use square brakets
(<code class="docutils literal notranslate"><span class="pre">[</span> <span class="pre">item</span> <span class="pre">]</span></code>) for optional items, <code class="docutils literal notranslate"><span class="pre">*</span></code> and <code class="docutils literal notranslate"><span class="pre">+</span></code> for repeated items (where <code class="docutils literal notranslate"><span class="pre">+</span></code> imply at least one).</li>
<li>The grammar will also use the following convention for convenience: non-terminal term will be lowercase (and link to
their definition) while terminal keywords will be provided “all caps”. Note however that keywords are
<a class="reference internal" href="#identifiers"><span class="std std-ref">Identifiers and keywords</span></a> and are thus case insensitive in practice. We will also define some early construction using
regexp, which we’ll indicate with <code class="docutils literal notranslate"><span class="pre">re(&lt;some</span> <span class="pre">regular</span> <span class="pre">expression&gt;)</span></code>.</li>
<li>The grammar is provided for documentation purposes and leave some minor details out. For instance, the comma on the
last column definition in a <code class="docutils literal notranslate"><span class="pre">CREATE</span> <span class="pre">TABLE</span></code> statement is optional but supported if present even though the grammar in
this document suggests otherwise. Also, not everything accepted by the grammar is necessarily valid CQL.</li>
<li>References to keywords or pieces of CQL code in running text will be shown in a <code class="docutils literal notranslate"><span class="pre">fixed-width</span> <span class="pre">font</span></code>.</li>
</ul>
</div>
<div class="section" id="identifiers">
<span id="identifiers-and-keywords"></span><h2>Identifiers and keywords<a class="headerlink" href="#identifiers" title="Permalink to this headline"></a></h2>
<p>The CQL language uses <em>identifiers</em> (or <em>names</em>) to identify tables, columns and other objects. An identifier is a token
matching the regular expression <code class="docutils literal notranslate"><span class="pre">[a-zA-Z][a-zA-Z0-9_]*</span></code>.</p>
<p>A number of such identifiers, like <code class="docutils literal notranslate"><span class="pre">SELECT</span></code> or <code class="docutils literal notranslate"><span class="pre">WITH</span></code>, are <em>keywords</em>. They have a fixed meaning for the language
and most are reserved. The list of those keywords can be found in <a class="reference internal" href="appendices.html#appendix-a"><span class="std std-ref">Appendix A: CQL Keywords</span></a>.</p>
<p>Identifiers and (unquoted) keywords are case insensitive. Thus <code class="docutils literal notranslate"><span class="pre">SELECT</span></code> is the same than <code class="docutils literal notranslate"><span class="pre">select</span></code> or <code class="docutils literal notranslate"><span class="pre">sElEcT</span></code>, and
<code class="docutils literal notranslate"><span class="pre">myId</span></code> is the same than <code class="docutils literal notranslate"><span class="pre">myid</span></code> or <code class="docutils literal notranslate"><span class="pre">MYID</span></code>. A convention often used (in particular by the samples of this
documentation) is to use upper case for keywords and lower case for other identifiers.</p>
<p>There is a second kind of identifiers called <em>quoted identifiers</em> defined by enclosing an arbitrary sequence of
characters (non empty) in double-quotes(<code class="docutils literal notranslate"><span class="pre">&quot;</span></code>). Quoted identifiers are never keywords. Thus <code class="docutils literal notranslate"><span class="pre">&quot;select&quot;</span></code> is not a
reserved keyword and can be used to refer to a column (note that using this is particularly advised), while <code class="docutils literal notranslate"><span class="pre">select</span></code>
would raise a parsing error. Also, contrarily to unquoted identifiers and keywords, quoted identifiers are case
sensitive (<code class="docutils literal notranslate"><span class="pre">&quot;My</span> <span class="pre">Quoted</span> <span class="pre">Id&quot;</span></code> is <em>different</em> from <code class="docutils literal notranslate"><span class="pre">&quot;my</span> <span class="pre">quoted</span> <span class="pre">id&quot;</span></code>). A fully lowercase quoted identifier that matches
<code class="docutils literal notranslate"><span class="pre">[a-zA-Z][a-zA-Z0-9_]*</span></code> is however <em>equivalent</em> to the unquoted identifier obtained by removing the double-quote (so
<code class="docutils literal notranslate"><span class="pre">&quot;myid&quot;</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">myid</span></code> and to <code class="docutils literal notranslate"><span class="pre">myId</span></code> but different from <code class="docutils literal notranslate"><span class="pre">&quot;myId&quot;</span></code>). Inside a quoted identifier, the
double-quote character can be repeated to escape it, so <code class="docutils literal notranslate"><span class="pre">&quot;foo</span> <span class="pre">&quot;&quot;</span> <span class="pre">bar&quot;</span></code> is a valid identifier.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><em>quoted identifiers</em> allows to declare columns with arbitrary names, and those can sometime clash with
specific names used by the server. For instance, when using conditional update, the server will respond with a
result-set containing a special result named <code class="docutils literal notranslate"><span class="pre">&quot;[applied]&quot;</span></code>. If you’ve declared a column with such a name, this
could potentially confuse some tools and should be avoided. In general, unquoted identifiers should be preferred but
if you use quoted identifiers, it is strongly advised to avoid any name enclosed by squared brackets (like
<code class="docutils literal notranslate"><span class="pre">&quot;[applied]&quot;</span></code>) and any name that looks like a function call (like <code class="docutils literal notranslate"><span class="pre">&quot;f(x)&quot;</span></code>).</p>
</div>
<p>More formally, we have:</p>
<pre>
<strong id="grammar-token-identifier">identifier </strong> ::= <a class="reference internal" href="#grammar-token-unquoted-identifier"><code class="xref docutils literal notranslate"><span class="pre">unquoted_identifier</span></code></a> | <a class="reference internal" href="#grammar-token-quoted-identifier"><code class="xref docutils literal notranslate"><span class="pre">quoted_identifier</span></code></a>
<strong id="grammar-token-unquoted-identifier">unquoted_identifier</strong> ::= re('[a-zA-Z][a-zA-Z0-9_]*')
<strong id="grammar-token-quoted-identifier">quoted_identifier </strong> ::= '&quot;' (any character where &quot; can appear if doubled)+ '&quot;'
</pre>
</div>
<div class="section" id="constants">
<span id="id2"></span><h2>Constants<a class="headerlink" href="#constants" title="Permalink to this headline"></a></h2>
<p>CQL defines the following kind of <em>constants</em>:</p>
<pre>
<strong id="grammar-token-constant">constant</strong> ::= <a class="reference internal" href="#grammar-token-string"><code class="xref docutils literal notranslate"><span class="pre">string</span></code></a> | <a class="reference internal" href="#grammar-token-integer"><code class="xref docutils literal notranslate"><span class="pre">integer</span></code></a> | <a class="reference internal" href="#grammar-token-float"><code class="xref docutils literal notranslate"><span class="pre">float</span></code></a> | <a class="reference internal" href="#grammar-token-boolean"><code class="xref docutils literal notranslate"><span class="pre">boolean</span></code></a> | <a class="reference internal" href="#grammar-token-uuid"><code class="xref docutils literal notranslate"><span class="pre">uuid</span></code></a> | <a class="reference internal" href="#grammar-token-blob"><code class="xref docutils literal notranslate"><span class="pre">blob</span></code></a> | NULL
<strong id="grammar-token-string">string </strong> ::= '\'' (any character where ' can appear if doubled)+ '\''
'$$' (any character other than '$$') '$$'
<strong id="grammar-token-integer">integer </strong> ::= re('-?[0-9]+')
<strong id="grammar-token-float">float </strong> ::= re('-?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9+])?') | NAN | INFINITY
<strong id="grammar-token-boolean">boolean </strong> ::= TRUE | FALSE
<strong id="grammar-token-uuid">uuid </strong> ::= <a class="reference internal" href="#grammar-token-hex"><code class="xref docutils literal notranslate"><span class="pre">hex</span></code></a>{8}-<a class="reference internal" href="#grammar-token-hex"><code class="xref docutils literal notranslate"><span class="pre">hex</span></code></a>{4}-<a class="reference internal" href="#grammar-token-hex"><code class="xref docutils literal notranslate"><span class="pre">hex</span></code></a>{4}-<a class="reference internal" href="#grammar-token-hex"><code class="xref docutils literal notranslate"><span class="pre">hex</span></code></a>{4}-<a class="reference internal" href="#grammar-token-hex"><code class="xref docutils literal notranslate"><span class="pre">hex</span></code></a>{12}
<strong id="grammar-token-hex">hex </strong> ::= re(&quot;[0-9a-fA-F]&quot;)
<strong id="grammar-token-blob">blob </strong> ::= '0' ('x' | 'X') <a class="reference internal" href="#grammar-token-hex"><code class="xref docutils literal notranslate"><span class="pre">hex</span></code></a>+
</pre>
<p>In other words:</p>
<ul class="simple">
<li>A string constant is an arbitrary sequence of characters enclosed by single-quote(<code class="docutils literal notranslate"><span class="pre">'</span></code>). A single-quote
can be included by repeating it, e.g. <code class="docutils literal notranslate"><span class="pre">'It''s</span> <span class="pre">raining</span> <span class="pre">today'</span></code>. Those are not to be confused with quoted
<a class="reference internal" href="#identifiers"><span class="std std-ref">Identifiers and keywords</span></a> that use double-quotes. Alternatively, a string can be defined by enclosing the arbitrary sequence
of characters by two dollar characters, in which case single-quote can be used without escaping (<code class="docutils literal notranslate"><span class="pre">$$It's</span> <span class="pre">raining</span>
<span class="pre">today$$</span></code>). That latter form is often used when defining <a class="reference internal" href="functions.html#udfs"><span class="std std-ref">user-defined functions</span></a> to avoid having to
escape single-quote characters in function body (as they are more likely to occur than <code class="docutils literal notranslate"><span class="pre">$$</span></code>).</li>
<li>Integer, float and boolean constant are defined as expected. Note however than float allows the special <code class="docutils literal notranslate"><span class="pre">NaN</span></code> and
<code class="docutils literal notranslate"><span class="pre">Infinity</span></code> constants.</li>
<li>CQL supports <a class="reference external" href="https://en.wikipedia.org/wiki/Universally_unique_identifier">UUID</a> constants.</li>
<li>Blobs content are provided in hexadecimal and prefixed by <code class="docutils literal notranslate"><span class="pre">0x</span></code>.</li>
<li>The special <code class="docutils literal notranslate"><span class="pre">NULL</span></code> constant denotes the absence of value.</li>
</ul>
<p>For how these constants are typed, see the <a class="reference internal" href="types.html#data-types"><span class="std std-ref">Data Types</span></a> section.</p>
</div>
<div class="section" id="terms">
<h2>Terms<a class="headerlink" href="#terms" title="Permalink to this headline"></a></h2>
<p>CQL has the notion of a <em>term</em>, which denotes the kind of values that CQL support. Terms are defined by:</p>
<pre>
<strong id="grammar-token-term">term </strong> ::= <a class="reference internal" href="#grammar-token-constant"><code class="xref docutils literal notranslate"><span class="pre">constant</span></code></a> | <a class="reference internal" href="#grammar-token-literal"><code class="xref docutils literal notranslate"><span class="pre">literal</span></code></a> | <a class="reference internal" href="#grammar-token-function-call"><code class="xref docutils literal notranslate"><span class="pre">function_call</span></code></a> | <a class="reference internal" href="#grammar-token-arithmetic-operation"><code class="xref docutils literal notranslate"><span class="pre">arithmetic_operation</span></code></a> | <a class="reference internal" href="#grammar-token-type-hint"><code class="xref docutils literal notranslate"><span class="pre">type_hint</span></code></a> | <a class="reference internal" href="#grammar-token-bind-marker"><code class="xref docutils literal notranslate"><span class="pre">bind_marker</span></code></a>
<strong id="grammar-token-literal">literal </strong> ::= <a class="reference internal" href="types.html#grammar-token-collection-literal"><code class="xref docutils literal notranslate"><span class="pre">collection_literal</span></code></a> | <a class="reference internal" href="types.html#grammar-token-udt-literal"><code class="xref docutils literal notranslate"><span class="pre">udt_literal</span></code></a> | <a class="reference internal" href="types.html#grammar-token-tuple-literal"><code class="xref docutils literal notranslate"><span class="pre">tuple_literal</span></code></a>
<strong id="grammar-token-function-call">function_call </strong> ::= <a class="reference internal" href="#grammar-token-identifier"><code class="xref docutils literal notranslate"><span class="pre">identifier</span></code></a> '(' [ <a class="reference internal" href="#grammar-token-term"><code class="xref docutils literal notranslate"><span class="pre">term</span></code></a> (',' <a class="reference internal" href="#grammar-token-term"><code class="xref docutils literal notranslate"><span class="pre">term</span></code></a>)* ] ')'
<strong id="grammar-token-arithmetic-operation">arithmetic_operation</strong> ::= '-' <a class="reference internal" href="#grammar-token-term"><code class="xref docutils literal notranslate"><span class="pre">term</span></code></a> | <a class="reference internal" href="#grammar-token-term"><code class="xref docutils literal notranslate"><span class="pre">term</span></code></a> ('+' | '-' | '*' | '/' | '%') <a class="reference internal" href="#grammar-token-term"><code class="xref docutils literal notranslate"><span class="pre">term</span></code></a>
<strong id="grammar-token-type-hint">type_hint </strong> ::= '(' <a class="reference internal" href="types.html#grammar-token-cql-type"><code class="xref docutils literal notranslate"><span class="pre">cql_type</span></code></a> `)` term
<strong id="grammar-token-bind-marker">bind_marker </strong> ::= '?' | ':' <a class="reference internal" href="#grammar-token-identifier"><code class="xref docutils literal notranslate"><span class="pre">identifier</span></code></a>
</pre>
<p>A term is thus one of:</p>
<ul class="simple">
<li>A <a class="reference internal" href="#constants"><span class="std std-ref">constant</span></a>.</li>
<li>A literal for either <a class="reference internal" href="types.html#collections"><span class="std std-ref">a collection</span></a>, <a class="reference internal" href="types.html#udts"><span class="std std-ref">a user-defined type</span></a> or <a class="reference internal" href="types.html#tuples"><span class="std std-ref">a tuple</span></a>
(see the linked sections for details).</li>
<li>A function call: see <a class="reference internal" href="functions.html#cql-functions"><span class="std std-ref">the section on functions</span></a> for details on which <a class="reference internal" href="functions.html#native-functions"><span class="std std-ref">native function</span></a> exists and how to define your own <a class="reference internal" href="functions.html#udfs"><span class="std std-ref">user-defined ones</span></a>.</li>
<li>An arithmetic operation between terms. see <a class="reference internal" href="operators.html#arithmetic-operators"><span class="std std-ref">the section on arithmetic operations</span></a></li>
<li>A <em>type hint</em>: see the <span class="xref std std-ref">related section</span> for details.</li>
<li>A bind marker, which denotes a variable to be bound at execution time. See the section on <a class="reference internal" href="#prepared-statements"><span class="std std-ref">Prepared Statements</span></a>
for details. A bind marker can be either anonymous (<code class="docutils literal notranslate"><span class="pre">?</span></code>) or named (<code class="docutils literal notranslate"><span class="pre">:some_name</span></code>). The latter form provides a more
convenient way to refer to the variable for binding it and should generally be preferred.</li>
</ul>
</div>
<div class="section" id="comments">
<h2>Comments<a class="headerlink" href="#comments" title="Permalink to this headline"></a></h2>
<p>A comment in CQL is a line beginning by either double dashes (<code class="docutils literal notranslate"><span class="pre">--</span></code>) or double slash (<code class="docutils literal notranslate"><span class="pre">//</span></code>).</p>
<p>Multi-line comments are also supported through enclosure within <code class="docutils literal notranslate"><span class="pre">/*</span></code> and <code class="docutils literal notranslate"><span class="pre">*/</span></code> (but nesting is not supported).</p>
<div class="highlight-cql notranslate"><div class="highlight"><pre><span></span><span class="c1">-- This is a comment</span>
<span class="c1">// This is a comment too</span>
<span class="cm">/* This is</span>
<span class="cm"> a multi-line comment */</span>
</pre></div>
</div>
</div>
<div class="section" id="statements">
<h2>Statements<a class="headerlink" href="#statements" title="Permalink to this headline"></a></h2>
<p>CQL consists of statements that can be divided in the following categories:</p>
<ul class="simple">
<li><a class="reference internal" href="ddl.html#data-definition"><span class="std std-ref">Data Definition</span></a> statements, to define and change how the data is stored (keyspaces and tables).</li>
<li><a class="reference internal" href="dml.html#data-manipulation"><span class="std std-ref">Data Manipulation</span></a> statements, for selecting, inserting and deleting data.</li>
<li><a class="reference internal" href="indexes.html#secondary-indexes"><span class="std std-ref">Secondary Indexes</span></a> statements.</li>
<li><a class="reference internal" href="mvs.html#materialized-views"><span class="std std-ref">Materialized Views</span></a> statements.</li>
<li><a class="reference internal" href="security.html#cql-roles"><span class="std std-ref">Database Roles</span></a> statements.</li>
<li><a class="reference internal" href="security.html#cql-permissions"><span class="std std-ref">Permissions</span></a> statements.</li>
<li><a class="reference internal" href="functions.html#udfs"><span class="std std-ref">User-Defined Functions</span></a> statements.</li>
<li><a class="reference internal" href="types.html#udts"><span class="std std-ref">User-Defined Types</span></a> statements.</li>
<li><a class="reference internal" href="triggers.html#cql-triggers"><span class="std std-ref">Triggers</span></a> statements.</li>
</ul>
<p>All the statements are listed below and are described in the rest of this documentation (see links above):</p>
<pre>
<strong id="grammar-token-cql-statement">cql_statement </strong> ::= <a class="reference internal" href="#grammar-token-statement"><code class="xref docutils literal notranslate"><span class="pre">statement</span></code></a> [ ';' ]
<strong id="grammar-token-statement">statement </strong> ::= <a class="reference internal" href="#grammar-token-ddl-statement"><code class="xref docutils literal notranslate"><span class="pre">ddl_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-dml-statement"><code class="xref docutils literal notranslate"><span class="pre">dml_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-secondary-index-statement"><code class="xref docutils literal notranslate"><span class="pre">secondary_index_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-materialized-view-statement"><code class="xref docutils literal notranslate"><span class="pre">materialized_view_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-role-or-permission-statement"><code class="xref docutils literal notranslate"><span class="pre">role_or_permission_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-udf-statement"><code class="xref docutils literal notranslate"><span class="pre">udf_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-udt-statement"><code class="xref docutils literal notranslate"><span class="pre">udt_statement</span></code></a>
| <a class="reference internal" href="#grammar-token-trigger-statement"><code class="xref docutils literal notranslate"><span class="pre">trigger_statement</span></code></a>
<strong id="grammar-token-ddl-statement">ddl_statement </strong> ::= <a class="reference internal" href="ddl.html#grammar-token-use-statement"><code class="xref docutils literal notranslate"><span class="pre">use_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-create-keyspace-statement"><code class="xref docutils literal notranslate"><span class="pre">create_keyspace_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-alter-keyspace-statement"><code class="xref docutils literal notranslate"><span class="pre">alter_keyspace_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-drop-keyspace-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_keyspace_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-create-table-statement"><code class="xref docutils literal notranslate"><span class="pre">create_table_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-alter-table-statement"><code class="xref docutils literal notranslate"><span class="pre">alter_table_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-drop-table-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_table_statement</span></code></a>
| <a class="reference internal" href="ddl.html#grammar-token-truncate-statement"><code class="xref docutils literal notranslate"><span class="pre">truncate_statement</span></code></a>
<strong id="grammar-token-dml-statement">dml_statement </strong> ::= <a class="reference internal" href="dml.html#grammar-token-select-statement"><code class="xref docutils literal notranslate"><span class="pre">select_statement</span></code></a>
| <a class="reference internal" href="dml.html#grammar-token-insert-statement"><code class="xref docutils literal notranslate"><span class="pre">insert_statement</span></code></a>
| <a class="reference internal" href="dml.html#grammar-token-update-statement"><code class="xref docutils literal notranslate"><span class="pre">update_statement</span></code></a>
| <a class="reference internal" href="dml.html#grammar-token-delete-statement"><code class="xref docutils literal notranslate"><span class="pre">delete_statement</span></code></a>
| <a class="reference internal" href="dml.html#grammar-token-batch-statement"><code class="xref docutils literal notranslate"><span class="pre">batch_statement</span></code></a>
<strong id="grammar-token-secondary-index-statement">secondary_index_statement </strong> ::= <a class="reference internal" href="indexes.html#grammar-token-create-index-statement"><code class="xref docutils literal notranslate"><span class="pre">create_index_statement</span></code></a>
| <a class="reference internal" href="indexes.html#grammar-token-drop-index-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_index_statement</span></code></a>
<strong id="grammar-token-materialized-view-statement">materialized_view_statement </strong> ::= <a class="reference internal" href="mvs.html#grammar-token-create-materialized-view-statement"><code class="xref docutils literal notranslate"><span class="pre">create_materialized_view_statement</span></code></a>
| <a class="reference internal" href="mvs.html#grammar-token-drop-materialized-view-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_materialized_view_statement</span></code></a>
<strong id="grammar-token-role-or-permission-statement">role_or_permission_statement</strong> ::= <a class="reference internal" href="security.html#grammar-token-create-role-statement"><code class="xref docutils literal notranslate"><span class="pre">create_role_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-alter-role-statement"><code class="xref docutils literal notranslate"><span class="pre">alter_role_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-drop-role-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_role_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-grant-role-statement"><code class="xref docutils literal notranslate"><span class="pre">grant_role_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-revoke-role-statement"><code class="xref docutils literal notranslate"><span class="pre">revoke_role_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-list-roles-statement"><code class="xref docutils literal notranslate"><span class="pre">list_roles_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-grant-permission-statement"><code class="xref docutils literal notranslate"><span class="pre">grant_permission_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-revoke-permission-statement"><code class="xref docutils literal notranslate"><span class="pre">revoke_permission_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-list-permissions-statement"><code class="xref docutils literal notranslate"><span class="pre">list_permissions_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-create-user-statement"><code class="xref docutils literal notranslate"><span class="pre">create_user_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-alter-user-statement"><code class="xref docutils literal notranslate"><span class="pre">alter_user_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-drop-user-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_user_statement</span></code></a>
| <a class="reference internal" href="security.html#grammar-token-list-users-statement"><code class="xref docutils literal notranslate"><span class="pre">list_users_statement</span></code></a>
<strong id="grammar-token-udf-statement">udf_statement </strong> ::= <a class="reference internal" href="functions.html#grammar-token-create-function-statement"><code class="xref docutils literal notranslate"><span class="pre">create_function_statement</span></code></a>
| <a class="reference internal" href="functions.html#grammar-token-drop-function-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_function_statement</span></code></a>
| <a class="reference internal" href="functions.html#grammar-token-create-aggregate-statement"><code class="xref docutils literal notranslate"><span class="pre">create_aggregate_statement</span></code></a>
| <a class="reference internal" href="functions.html#grammar-token-drop-aggregate-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_aggregate_statement</span></code></a>
<strong id="grammar-token-udt-statement">udt_statement </strong> ::= <a class="reference internal" href="types.html#grammar-token-create-type-statement"><code class="xref docutils literal notranslate"><span class="pre">create_type_statement</span></code></a>
| <a class="reference internal" href="types.html#grammar-token-alter-type-statement"><code class="xref docutils literal notranslate"><span class="pre">alter_type_statement</span></code></a>
| <a class="reference internal" href="types.html#grammar-token-drop-type-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_type_statement</span></code></a>
<strong id="grammar-token-trigger-statement">trigger_statement </strong> ::= <a class="reference internal" href="triggers.html#grammar-token-create-trigger-statement"><code class="xref docutils literal notranslate"><span class="pre">create_trigger_statement</span></code></a>
| <a class="reference internal" href="triggers.html#grammar-token-drop-trigger-statement"><code class="xref docutils literal notranslate"><span class="pre">drop_trigger_statement</span></code></a>
</pre>
</div>
<div class="section" id="prepared-statements">
<span id="id3"></span><h2>Prepared Statements<a class="headerlink" href="#prepared-statements" title="Permalink to this headline"></a></h2>
<p>CQL supports <em>prepared statements</em>. Prepared statements are an optimization that allows to parse a query only once but
execute it multiple times with different concrete values.</p>
<p>Any statement that uses at least one bind marker (see <a class="reference internal" href="#grammar-token-bind-marker"><code class="xref std std-token docutils literal notranslate"><span class="pre">bind_marker</span></code></a>) will need to be <em>prepared</em>. After which the statement
can be <em>executed</em> by provided concrete values for each of its marker. The exact details of how a statement is prepared
and then executed depends on the CQL driver used and you should refer to your driver documentation.</p>
</div>
</div>
<div class="doc-prev-next-links" role="navigation" aria-label="footer navigation">
<a href="types.html" class="btn btn-default pull-right " role="button" title="Data Types" accesskey="n">Next <span class="glyphicon glyphicon-circle-arrow-right" aria-hidden="true"></span></a>
<a href="index.html" class="btn btn-default" role="button" title="The Cassandra Query Language (CQL)" accesskey="p"><span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span> Previous</a>
</div>
</div>
</div>
</div>
</div>
</div>
<hr />
<footer>
<div class="container">
<div class="col-md-4 social-blk">
<span class="social">
<a href="https://twitter.com/cassandra"
class="twitter-follow-button"
data-show-count="false" data-size="large">Follow @cassandra</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<a href="https://twitter.com/intent/tweet?button_hashtag=cassandra"
class="twitter-hashtag-button"
data-size="large"
data-related="ApacheCassandra">Tweet #cassandra</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</span>
<a class="subscribe-rss icon-link" href="/feed.xml" title="Subscribe to Blog via RSS">
<span><i class="fa fa-rss"></i></span>
</a>
</div>
<div class="col-md-8 trademark">
<p>&copy; 2016 <a href="http://apache.org">The Apache Software Foundation</a>.
Apache, the Apache feather logo, and Apache Cassandra are trademarks of The Apache Software Foundation.
<p>
</div>
</div><!-- /.container -->
</footer>
<!-- Javascript. Placed here so pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="./../../../js/underscore-min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="./../../../js/doctools.js"></script>
<script src="./../../../js/searchtools.js"></script>
<script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: "", VERSION: "", COLLAPSE_INDEX: false, FILE_SUFFIX: ".html", HAS_SOURCE: false, SOURCELINK_SUFFIX: ".txt" }; </script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("UA-11583863-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>