AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Problem quoting alias for columns #606

Open loque opened 8 years ago

loque commented 8 years ago

I've found a problem when alasql parses the query string. When trying to give a column an alias with spaces I got errors when using " and '. I think it would be useful to explain in the wiki that aliases can only be quoted like this:

SELECT SUM(I_dont_like_this_name) AS `Fancy Name` FROM table_name

For reference, the error messages I got where, in Chromium SyntaxError: Unexpected identifier, and in Firefox SyntaxError: missin ] in index expression

agershun commented 8 years ago

Hi Lucas,

  1. You also can use [ ] to enclose these 'multiword' name (not only backquotes ) like :
SELECT ... AS [Fancy Name] FROM table_name
  1. When you wrote about quotes in the alias names, did you mean this syntax like this:
SELECT ... AS "Fancy Name" FROM table_name

I will check the parser grammar rules for this syntax.

loque commented 8 years ago

Hi @agershun,

Good to know about the []!

Exactly, the syntax in the following examples did not work:

SELECT ... AS "Fancy Name" FROM table_name
SELECT ... AS 'Fancy Name' FROM table_name

Btw, I really appreciate the work you've done with AlaSQL!