0

I'm getting the following error when trying to execute the bq query:

FATAL Flags parsing error: Unknown command line flag '-v'

The query is simple and I think the problem is inside the concat function, because I'm trying to concat a curl command and there I have a -v flag, the query is below:

select concat('curl -v https://api.com.br/push.json  -H \"Content-Type: application/json\" -H \"x_application: WebApp\" -H -X POST -d \'{\"pushes\":[\''
    ,string_agg(to_json_string(t)),']}\'') as json

How can I escape the -v to not getting this error?

Thanks

7
  • are you using the select statement to build curl command that then you execute outside of BigQuery and that is where you are getting error? Commented Jul 27, 2017 at 21:22
  • Yes, exactly this @MikhailBerlyant Commented Jul 27, 2017 at 21:24
  • So you should know which command line you want to build - right - this looks to me like curl related more than bigquery. so what is the curl command you expect to build and how it is different from what you get by running above query? Commented Jul 27, 2017 at 21:25
  • I don't quite understand. When you run bq query "select concat(...)" you get the error message or after you get the return of the select statement and run the resulting curl command is that you get the error message? Commented Jul 27, 2017 at 21:32
  • Hi @MikhailBerlyant, the problem is not in curl, I'm trying to build a curl command inside bigquery, the query is running perfectly in bigquery wepapp, but is not running when I ran on bigquery command line. Commented Jul 27, 2017 at 21:56

1 Answer 1

2

Try running this:

bq query "select concat('curl -v https://api.com.br/push.json  -H \"Content-Type: application/json\" -H \"x_application: WebApp\" -H -X POST -d \'{\"pushes\":[\'',string_agg(to_json_string(t)),']}\'') as json"

In order to prevent bash interpretation from the string, maybe reading the query from a file might help as well. If your query is something like:

WITH data AS(
select [1, 2] AS t
)

select
concat('curl -v https://api.com.br/push.json  -H \"Content-Type: application/json\" -H \"x_application: WebApp\" -H -X POST -d \'{\"pushes\":[\'',string_agg(to_json_string(t)),']}\'') as json
FROM
data

You could save it for instance in a file "query.sql" and then run the command:

cat query.sql | bq query --use_legacy_sql=False
Sign up to request clarification or add additional context in comments.

Comments

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.