5

I have a query that generates rows for insertion into a table. The query references tables in different projects. The project names include hyphen (ex. abc-xyz). When I try to use bq command and use ` to enclose the project name I get error and if I don't I get error and if I try single or double quotes or brackets still get error. Is there a way to reference another project that has hyphen in its name in a query using bq command?

Here is what I get when I run a sample command:

bq query --use_legacy_sql=false "select account_id, max(updated) max_updated, max(_PARTITIONTIME) max_pt from abc-xyz.myset.mytable group by 1"

-bash: abc-xyz: command not found

When I copy and paste that same query strin in the UI, it works fine.

Thanks

2
  • What is the command that you are trying to run? Commented Mar 20, 2017 at 18:59
  • I added the command I was running to the post Commented Mar 20, 2017 at 19:39

2 Answers 2

3

In addition to Mikhail's suggestion, if you have content in your query that conflicts with Bash syntax (such as quotes and dollar signs), another approach is to put your query in a file, e.g. my_query.sql, and then run:

bq query --use_legacy_sql=false < my_query.sql

This will pipe the unmodified contents of the file to the bq tool.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the suggestion. The problem with that approach is that we have a series of (sql) commands that need to be executed and it might include some other commands (like loading a file using API call). We need to see all the processing/commands that happen for one job in one place, not spread out in files.
This worked for me
3

Ideally, you should enclose whole table reference into back-ticks - not just project itself

So, instead of

`abc-xyz`.myset.mytable  

try

`abc-xyz.myset.mytable`

1 Comment

Thanks for the suggestion. Tried it and the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.