mozilla/moz-sql-parser

Formatter incorrectly formats column labels with spaces

Closed this issue · 1 comments

The Formatter doesn't double quote column aliases that have spaces in them, and they end up treated as plain text, making them invalid.

For example :

{'select': [{'value': 'NomPropriete', 'name': 'Categorie'}, {'value': {'round': [{'avg': 'NotePonderee'}, 2]}, 'name': 'Moyenne des notes'}, {'value': {'round': [{'avg': 'Complexite'}, 2]}, 'name': 'Complexite moyenne'}],
'from': ['Propriete', 'Categorie', 'Jeu'], 
'where': {'and': [{'eq': ['IdPropriete', 'IdCategorie']}, {'eq': ['Categorie.IdJeu', 'Jeu.IdJeu']}, {'gt': ['NotePonderee', 0]}]},
'groupby': [{'value': 'IdPropriete'}, {'value': 'NomPropriete'}],
'orderby': [{'value': 'Moyenne des notes', 'sort': 'desc'}, {'value': 'Complexite moyenne', 'sort': 'desc'}]}

is formatted as

SELECT NomPropriete AS Categorie, ROUND(AVG(NotePonderee), 2) AS Moyenne des notes, ROUND(AVG(Complexite), 2) AS Complexite moyenne 
FROM Propriete, Categorie, Jeu
WHERE IdPropriete = IdCategorie 
AND Categorie.IdJeu = Jeu.IdJeu 
AND NotePonderee > 0 
GROUP BY IdPropriete, NomPropriete 
ORDER BY Moyenne des notes DESC,Complexite moyenne DESC

test and fix added here:

c82300b

will be merged shortly