Tuesday, 27 August 2013

Replacing apostrophe or quotes in bq SQL

Replacing apostrophe or quotes in bq SQL

I'm new to using bq, Big Query command line utility. I have a more complex
SQL clause that unfortunately has both apostrophe and quote characters
within the SQL statement. Since both characters are in the SQL statement
I'm looking for some replacement for them, otherwise one or the other will
be interpretted as an "end of query" delimitter.
Below is the query that I am trying to run, which works great on the Big
Query html interface, but not so great using bq command line utility.
Suggestions on replacing the apostrophes or quotes to get this thing
running? Is there any option to pass file content into the bq query
command so the complex query could be stored in a file? (also easier to
read in a file vs crammed onto one line).
bq query 'SELECT regexp_extract(meta, r'\"bldid\":\"(.*?)\"') as bldid
FROM stuff.201308010000 LIMIT 10'
[EDIT] After playing around with this a bit more, it looks like this was a
simple fix. If quotes are used for BEG and END delimiters the query works.
bq query "SELECT regexp_extract(meta, r'\"bldid\":\"(.*?)\"') as bldid
FROM stuff.201308010000 LIMIT 10"
Not sure why this didn't work for apostrophes to mark the beginning and
end of the query.

No comments:

Post a Comment