Using Couchbase server 7.1.5, I am creating indexes for a collection. I create them in the Couchbase UI as well as with the cbq command line tool. In the query, I use snake_case naming convention. I see that any naming with a hyphen needs to be surrounded by back tics.
An example from the docs:
SELECT a.country FROM default:`travel-sample`.inventory.airline a WHERE a.name = "Excel Airways";
An example of my queries:
CREATE INDEX index_anomalies_date ON room.ecmp.anomalies(date);
Is there a document that shows which special characters must be surrounded with back tics?
When I create my queries with and without back tics, I get the same results in the UI and with cbq. The indexes get created properly and can be inspected with:
Iām not explicitly declaring a namespace such as ādefaultā. If I use the default namespace in the query or omit it, I get the same results as seen by the results output above.
CREATE INDEX index_anomalies_date ON room.ecmp.anomalies(date);
CREATE INDEX index_anomalies_date ON default:room.ecmp.anomalies(date);
I didnāt find a list of characters that must be escaped. Itās safe to escape every bucket name and n1ql identifier. Also when an identifier is the same as a reserved word, it must be escaped.
The back-tics are not part of the name, so the resulting indexes will be the same. The back-tics are for parsing n1ql statements (or query-contexts for n1ql statements of namespace:bucketname.scope.collection)
the namespace is kind of a āfor future useā thing. Itās always ādefaultā.
āUnescaped identifiers cannot support the full range of identifiers allowed in a JSON document, but do support the most common ones with a simpler syntax.ā
I was just wondering if the lack of back-tics would cause a parsing issue but you clarify that in your answer to question 2.
namespace is optional (at present all couchbase buckets use default namespace). In memory keyspaces use system as namepsace
FYI: JSON schema less travel-sample without escape can be fields and - is minus arithmetic operations.
ex: Also valid
{"a-b":1, "a+b":9, "c.d":10, "c d":20, .....}
Also reserve words used as fields must be escaped
Reserve words, keyspace (i.e. bucket, scope, collection, aliases ) where identifier expected may give syntax error.
Some cases if conflict with fields and expression operators -,+,⦠may interpret wrongly.
SELECT a-b AS a1
FROM [ {"a-b":1, "a+b":9, "c.d":10, "c d":20, "a":30, "b":20 }] AS d;