| |
| |
| <!DOCTYPE html> |
| <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> |
| <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> |
| <head> |
| <meta charset="utf-8"> |
| |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| <title>Arithmetic Operators — Apache Cassandra Documentation v4.1</title> |
| |
| |
| |
| |
| |
| |
| |
| |
| <script type="text/javascript" src="../_static/js/modernizr.min.js"></script> |
| |
| |
| <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> |
| <script type="text/javascript" src="../_static/jquery.js"></script> |
| <script type="text/javascript" src="../_static/underscore.js"></script> |
| <script type="text/javascript" src="../_static/doctools.js"></script> |
| <script type="text/javascript" src="../_static/language_data.js"></script> |
| <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script> |
| |
| <script type="text/javascript" src="../_static/js/theme.js"></script> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> |
| <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
| <link rel="stylesheet" href="../_static/extra.css" type="text/css" /> |
| <link rel="index" title="Index" href="../genindex.html" /> |
| <link rel="search" title="Search" href="../search.html" /> |
| <link rel="next" title="JSON Support" href="json.html" /> |
| <link rel="prev" title="Functions" href="functions.html" /> |
| </head> |
| |
| <body class="wy-body-for-nav"> |
| |
| |
| <div class="wy-grid-for-nav"> |
| |
| <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
| <div class="wy-side-scroll"> |
| <div class="wy-side-nav-search" > |
| |
| |
| |
| <a href="../index.html" class="icon icon-home"> Apache Cassandra |
| |
| |
| |
| </a> |
| |
| |
| |
| |
| <div class="version"> |
| 4.1 |
| </div> |
| |
| |
| |
| |
| <div role="search"> |
| <form id="rtd-search-form" class="wy-form" action="../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search docs" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| |
| |
| </div> |
| |
| <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> |
| |
| |
| |
| |
| |
| |
| <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="../new/index.html">New Features in Apache Cassandra 4.0</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../architecture/index.html">Architecture</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"><a class="reference internal" href="definitions.html">Definitions</a></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 current"><a class="current reference internal" href="#">Arithmetic Operators</a><ul> |
| <li class="toctree-l3"><a class="reference internal" href="#number-arithmetic">Number Arithmetic</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#datetime-arithmetic">Datetime Arithmetic</a></li> |
| </ul> |
| </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="../data_modeling/index.html">Data Modeling</a></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> |
| </div> |
| </nav> |
| |
| <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
| |
| |
| <nav class="wy-nav-top" aria-label="top navigation"> |
| |
| <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| <a href="../index.html">Apache Cassandra</a> |
| |
| </nav> |
| |
| |
| <div class="wy-nav-content"> |
| |
| <div class="rst-content"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <div role="navigation" aria-label="breadcrumbs navigation"> |
| |
| <ul class="wy-breadcrumbs"> |
| |
| <li><a href="../index.html">Docs</a> »</li> |
| |
| <li><a href="index.html">The Cassandra Query Language (CQL)</a> »</li> |
| |
| <li>Arithmetic Operators</li> |
| |
| |
| <li class="wy-breadcrumbs-aside"> |
| |
| |
| <a href="../_sources/cql/operators.rst.txt" rel="nofollow"> View page source</a> |
| |
| |
| </li> |
| |
| </ul> |
| |
| |
| <hr/> |
| </div> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <div class="section" id="arithmetic-operators"> |
| <span id="id1"></span><h1>Arithmetic Operators<a class="headerlink" href="#arithmetic-operators" title="Permalink to this headline">ΒΆ</a></h1> |
| <p>CQL supports the following operators:</p> |
| <table class="docutils align-default"> |
| <colgroup> |
| <col style="width: 13%" /> |
| <col style="width: 87%" /> |
| </colgroup> |
| <thead> |
| <tr class="row-odd"><th class="head"><p>Operator</p></th> |
| <th class="head"><p>Description</p></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="row-even"><td><p>- (unary)</p></td> |
| <td><p>Negates operand</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>+</p></td> |
| <td><p>Addition</p></td> |
| </tr> |
| <tr class="row-even"><td><p>-</p></td> |
| <td><p>Substraction</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>*</p></td> |
| <td><p>Multiplication</p></td> |
| </tr> |
| <tr class="row-even"><td><p>/</p></td> |
| <td><p>Division</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>%</p></td> |
| <td><p>Returns the remainder of a division</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="section" id="number-arithmetic"> |
| <span id="id2"></span><h2>Number Arithmetic<a class="headerlink" href="#number-arithmetic" title="Permalink to this headline">ΒΆ</a></h2> |
| <p>All arithmetic operations are supported on numeric types or counters.</p> |
| <p>The return type of the operation will be based on the operand types:</p> |
| <table class="docutils align-default"> |
| <colgroup> |
| <col style="width: 13%" /> |
| <col style="width: 11%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| <col style="width: 10%" /> |
| </colgroup> |
| <thead> |
| <tr class="row-odd"><th class="head"><p>left/right</p></th> |
| <th class="head"><p>tinyint</p></th> |
| <th class="head"><p>smallint</p></th> |
| <th class="head"><p>int</p></th> |
| <th class="head"><p>bigint</p></th> |
| <th class="head"><p>counter</p></th> |
| <th class="head"><p>float</p></th> |
| <th class="head"><p>double</p></th> |
| <th class="head"><p>varint</p></th> |
| <th class="head"><p>decimal</p></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="row-even"><td><p><strong>tinyint</strong></p></td> |
| <td><p>tinyint</p></td> |
| <td><p>smallint</p></td> |
| <td><p>int</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>float</p></td> |
| <td><p>double</p></td> |
| <td><p>varint</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><strong>smallint</strong></p></td> |
| <td><p>smallint</p></td> |
| <td><p>smallint</p></td> |
| <td><p>int</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>float</p></td> |
| <td><p>double</p></td> |
| <td><p>varint</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-even"><td><p><strong>int</strong></p></td> |
| <td><p>int</p></td> |
| <td><p>int</p></td> |
| <td><p>int</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>float</p></td> |
| <td><p>double</p></td> |
| <td><p>varint</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><strong>bigint</strong></p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>varint</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-even"><td><p><strong>counter</strong></p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>bigint</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>varint</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><strong>float</strong></p></td> |
| <td><p>float</p></td> |
| <td><p>float</p></td> |
| <td><p>float</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>float</p></td> |
| <td><p>double</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-even"><td><p><strong>double</strong></p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>double</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><strong>varint</strong></p></td> |
| <td><p>varint</p></td> |
| <td><p>varint</p></td> |
| <td><p>varint</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| <tr class="row-even"><td><p><strong>decimal</strong></p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| <td><p>decimal</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <p><code class="docutils literal notranslate"><span class="pre">*</span></code>, <code class="docutils literal notranslate"><span class="pre">/</span></code> and <code class="docutils literal notranslate"><span class="pre">%</span></code> operators have a higher precedence level than <code class="docutils literal notranslate"><span class="pre">+</span></code> and <code class="docutils literal notranslate"><span class="pre">-</span></code> operator. By consequence, |
| they will be evaluated before. If two operator in an expression have the same precedence level, they will be evaluated |
| left to right based on their position in the expression.</p> |
| </div> |
| <div class="section" id="datetime-arithmetic"> |
| <span id="id3"></span><h2>Datetime Arithmetic<a class="headerlink" href="#datetime-arithmetic" title="Permalink to this headline">ΒΆ</a></h2> |
| <p>A <code class="docutils literal notranslate"><span class="pre">duration</span></code> can be added (+) or substracted (-) from a <code class="docutils literal notranslate"><span class="pre">timestamp</span></code> or a <code class="docutils literal notranslate"><span class="pre">date</span></code> to create a new |
| <code class="docutils literal notranslate"><span class="pre">timestamp</span></code> or <code class="docutils literal notranslate"><span class="pre">date</span></code>. So for instance:</p> |
| <div class="highlight-cql notranslate"><div class="highlight"><pre><span></span><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="n">myTable</span> <span class="k">WHERE</span> <span class="n">t</span> <span class="o">=</span> <span class="s1">'2017-01-01'</span> <span class="o">-</span> <span class="mf">2</span><span class="n">d</span> |
| </pre></div> |
| </div> |
| <p>will select all the records with a value of <code class="docutils literal notranslate"><span class="pre">t</span></code> which is in the last 2 days of 2016.</p> |
| </div> |
| </div> |
| |
| |
| </div> |
| |
| </div> |
| <footer> |
| |
| <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> |
| |
| <a href="json.html" class="btn btn-neutral float-right" title="JSON Support" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> |
| |
| |
| <a href="functions.html" class="btn btn-neutral float-left" title="Functions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> |
| |
| </div> |
| |
| |
| <hr/> |
| |
| <div role="contentinfo"> |
| <p> |
| © Copyright 2020, The Apache Cassandra team |
| |
| </p> |
| </div> |
| Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. |
| |
| </footer> |
| |
| </div> |
| </div> |
| |
| </section> |
| |
| </div> |
| |
| |
| |
| <script type="text/javascript"> |
| jQuery(function () { |
| SphinxRtdTheme.Navigation.enable(true); |
| }); |
| </script> |
| |
| |
| |
| |
| |
| |
| </body> |
| </html> |