N1QL query syntax problem (caused by backticks? examples don't work)

Trying to perform simple ‘SELECT * FROM x’ query fails with Node.js (confirmed with Node.js 5.1, 5.0, 4.2.2, and Node.js couchbase SDK 2.1.2 on OSX El Capitan 10.11.1 and Couchbase Server Community Edition 4.0.0-4051). I’m using Hapi, btw, but I’m not sure whether it’s relevant in this case.

I was able to perform the query by adding backticks, i.e. 'SELECT * FROM `x`', but this is not mentioned in the examples.

I was not able to perform N1QL queries using curl at all (bash doesn’t seem to like backticks and without backticks I get “syntax error - at -”).

EDIT: actually noticed that the use of backticks is mentioned here, but I’m still wondering how to get curl working.


  method: 'GET',
  path: '/query',
  handler: function(request, reply) {
    var query = Couchbase.N1qlQuery.fromString('SELECT * FROM travel-sample');
    console.log('Performing N1QL query: ' + query);
    bucket.query(query, function(err, res) {
      if (err) {
      } else {

Console log when accessing the route:

myhost:myhapiapp myuser$ gulp
[15:18:56] Using gulpfile ~/workspace/myhapiapp/gulpfile.js
[15:18:56] Starting 'default'...
[15:18:56] Finished 'default' after 1.97 ms
[15:18:56] [nodemon] 1.8.1
[15:18:56] [nodemon] to restart at any time, enter `rs`
[15:18:56] [nodemon] watching: *.*
[15:18:56] [nodemon] starting `node server.js`
Server running at: http://myhost.local:3000
Performing N1QL query: statement=SELECT%20*%20FROM%20travel-bucket
{ [Error: syntax error - at -]
  code: 3000,
  otherErrors: [],
  requestID: '56cc4476-0a8a-4a68-8af1-bb166e3f3af9' }

This is definitely due to the absence of backtick escaping. Your bucket is named travel-bucket (btw, is that a custom bucket or a typo on the sample bucket travel-sample?).

N1QL will by default interpret the dash as a “minus” operator which is illegal there, so you need to escape the whole token.

I don’t know about how to use backticks in curl (I usually use postman, a chrome extension/application that offers me a GUI for working with HTTP requests).