Is there a list of column references that will break query functions in Google Sheets? (column BY, OR)

104 Views Asked by At

I am using column references in a Google Sheets query and realized that column BY (Col #77) breaks my query, as BY is a special word in querying. The solution is to enclose BY in quotations (`BY`) within the query. Today I realized that OR (Col #408) was breaking my query as well. Is there a way I can identify what these words are ahead of time? I'm guessing column AND is also problematic.

Thanks!

3

There are 3 best solutions below

0
Mike Steelson On

In your situation, enclose the area with curly brackets and use ColX.

Example, replace =query(A:BY,"select A, BY") by =query({A:BY},"select Col1, Col77")

Note that x is not an absolute value but relative to the virtual matrix, i.e. =query({BX:BX,BY:BY,OR:OR},"select Col2, Col3 where Col1 is not null")

0
Daniel On

Mike's answer is a great workaround to this but if you're still looking for a list you can refer to the Google Sheets function list and their Query Language Reserved Words reference, so you can have an idea of what words are reserved in Sheets.

0
player0 On

see: https://developers.google.com/chart/interactive/docs/querylanguage#Reserved_Words

so, as per documentation, you will need to backquote only these 5:

`BY`
`OR`
`AND`
`ASC`
`NOT`

enter image description here