-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example requested: how to escape where
#80
Comments
What is the complete command you execute? What is your operating system? What is your shell? I'm going to assume Linux and Bash because that's what I use. I would use a command like this: athenacli -e /dev/stdin <<"EOF"
SELECT "table_name"
FROM "awsdatacatalog"."information_schema"."tables"
WHERE "table_schema" = 'information_schema';
EOF It gives me a CSV result.
The The Bash manual explains here documents and the Linux Documentation Project gives many examples. Why didn't your command work? I'm going to assume your complete command looked like this: athenacli -e '
SELECT "table_name"
FROM "awsdatacatalog"."information_schema"."tables"
WHERE "table_schema" = 'information_schema';
' That gives the following error:
To see why, echo '
SELECT "table_name"
FROM "awsdatacatalog"."information_schema"."tables"
WHERE "table_schema" = 'information_schema';
' Bash does not preserve the single quotes inside the the main single quotes.
From Bash's point of view the "inside" single quotes are not inside, but they end a string. Then Bash appends the next string, quoted or not. A simple example that shows the same effect: echo 'a'b'c'
|
There's an even simpler solution if you don't need to quote any column names: use double quotes around your query. athenacli -e "
SELECT table_name
FROM awsdatacatalog.information_schema.tables
WHERE table_schema = 'information_schema';
" |
I'd like to be able to execute the following query with
-e
, without writing asql
file. What's the best way to do this? Because I need both"
and'
I'm unsure how to escape in the context of-e 'my query string here'
.Naively executing this just returns a confusing error (it's mistaking my value for a column):
The text was updated successfully, but these errors were encountered: