A newer version of this documentation is available.

View Latest

N1QL Language Reference

  • concept
    +
    The N1QL reference guide describes the N1QL language structure and syntax. It provides reference information about the basic elements in N1QL which can be combined to build N1QL statements.

    N1QL Language Structure

    The N1QL language structure is composed of statements, expressions, and comments.

    Statements

    N1QL statements are categorized into the following groups:

    Comments

    N1QL supports block comments with the following syntax:

    /*  [ [text] | [newline] ]+  */
    Syntax diagram

    A block comment starts with /* and ends with */. The query engine ignores the start and end markers /* */, and any text between them.

    A block comment may start on a new line, or in the middle of a line after other N1QL statements. A block comment may contain line breaks.

    There may also be further N1QL statements on the same line after the end of a block comment — the query engine does not ignore these.

    Nested Path Expressions

    In N1QL, nested paths indicate an expression to access nested sub-documents within a JSON document or expression.

    For example, the latitude of a location in the type="airport" documents in the `travel-sample` are in the geo sub-document and can be addressed as the nested path `travel-sample`.geo.lat:

    SELECT airportname, city, geo, round(geo.lat) as latitude
    FROM `travel-sample` t1
    WHERE t1.type = "airport" LIMIT 1;
    
    [
      {
        "airportname": "Calais Dunkerque",
        "city": "Calais",
        "geo": {
          "alt": 12,
          "lat": 50.962097,
          "lon": 1.954764
        }
        "latitude": 51,
      }
    ]

    You can use nested operators to access sub-document fields within a document.