0

Is there a way to execute SQL queries on MongoDB if the collection's name contains special characters such as 1a84375b-9bd0-4ec3-9f93-536ce380f813? I encounter org.apache.calcite.sql.parser.impl.ParseException when I execute my statement. Are there any escape characters?

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Pete
  • 13
  • 4

1 Answers1

1

In Calcite SQL, you can quote identifiers (table names and column names). In the default dialect, you use double quotes. For example,

SELECT "a column"
FROM "a table with spaces in the name"

Also note that when if identifiers are quoted, Calcite retains their case (it does not convert to upper or lower case) and uses case-sensitive matching.

By the way, this is the same as Oracle and several other common SQL dialects.

Julian Hyde
  • 1,239
  • 7
  • 10
  • That works fine for me. I changed the default dialect in SQL_SERVER. Now, i encounter org.apache.calcite.sql.validate.SqlValidatorException: Table '6a3c9c9a-a607-46ad-8fca-7308d82d58a4' not found when i try to run SELECT [6a3c9c9a-a607-46ad-8fca-7308d82d58a4].id,[6a3c9c9a-a607-46ad-8fca-7308d82d58a4].name FROM [6a3c9c9a-a607-46ad-8fca-7308d82d58a4] against the MongoDB database. I already tried it with sqlline and verified with !tables the exist of 6a3c9c9a-a607-46ad-8fca-7308d82d58a4 as table name. – Pete Dec 20 '16 at 14:30