Reputation: 2878
I have a simple query like this:
SELECT IF(production_center='production center 1',total_sales_less_taxes,0)
as PC1_sales FROM ...
This fails with Query Failed Error: Unexpected.
depending on the value of the string 'production center 1'
for example if I change that string to 'NYC' which is also in the data base as a production_center value, it fails. If I change 'production center 1' to 'production center' it fails, but if I change it to 'production center xyzzy' its okay.
There is no pattern whatsoever to the failure mode.
The work around I am using is to replace production_center = ... with production_center CONTAINS '....'
which works fine.
Upvotes: 2
Views: 337
Reputation: 590
Here is working example (public shakespeare database):
SELECT IF(corpus='comedyoferrors',corpus_date,0), corpus
FROM [publicdata:samples.shakespeare]
WHERE corpus IN('comedyoferrors', '1kinghenryiv')
OR This ERROR in Big Query. I figure out that if I replace corpus_date by word_count then it fails. But if I use earlier field in condition (replace corpus by word) then is ok:
SELECT word, IF(word='ACT',word_count,0), corpus
FROM [publicdata:samples.shakespeare]
WHERE corpus IN('comedyoferrors', '1kinghenryiv')
So, the order of the fields matters.
Upvotes: 1