SELECT RAW Clause

SELECT RAW Clause

SELECT RAW specifies to make the resulting expression not be qualified; that is, the standard N1QL output (same as relational engines) returns tuples tagged with an alias, and the RAW qualifier removes this extra layer.

Note: RAW and ELEMENT are synonyms.

With a given projection list the N1QL service will produce an array of result sub-documents, each containing a sub-document for each element in the projection list.

Example 1a: A simple expression without the RAW qualifier.
SELECT {"a":1, "b":2};

Results:
[
  {
    "$1": {             / added line with alias
      "a": 1,
      "b": 2
    }
  }
]
Example 1b: The same simple expression with the RAW qualifier.
SELECT RAW {"a":1, "b":2};

Results:
[
  {                     / no added line with alias
    "a": 1,
    "b": 2
  }
]

There are times in which this extra layer might not be desirable since it requires extra output parsing. So the RAW qualifier specifies that the expression that follows not to be qualified, as shown in the next example.

Example 2a: List 5 airport cities alphabetically.
SELECT city FROM `travel-sample` WHERE type="airport" ORDER BY city limit 5;

Results:
[
  {
    "city": "Abbeville"
  },
  {
    "city": "Aberdeen"
  },
  {
    "city": "Aberdeen"
  },
  {
    "city": "Aberdeen"
  },
  {
    "city": "Abilene"
  }
]
Example 2b: List 5 airport cities alphabetically with the RAW qualifier.
SELECT RAW city FROM `travel-sample` WHERE type="airport" limit 3;

Results:
[
  "Abbeville",
  "Aberdeen",
  "Aberdeen",
  "Aberdeen",
  "Abilene"
]
Example 2c: List 5 unique airport cities alphabetically with the RAW qualifier.
SELECT DISTINCT RAW city FROM `travel-sample` WHERE type="airport" ORDER BY city limit 5;

Results:
[
  "Abbeville",
  "Aberdeen",
  "Abilene",
  "Adak Island",
  "Addison"
]