N1QL Language Reference
The N1QL reference guide describes the N1QL language structure, syntax, and shows how to run N1QL queries from a command line. It also 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:
-
Data Definition Language (DDL) statements to create indexes, modify indexes, and drop indexes.
-
Data Manipulation Language (DML) statements to select, insert, update, delete, and upsert data into JSON documents.
-
- Expressions
-
The following are the different types of N1QL expressions:
- Comments
-
N1QL supports block comments with the following syntax:
/* [ [text] | [newline] ]+ */
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, } ]
Dot Notation (.) is used to access sub-document fields within a document.