jupysql
jupysql copied to clipboard
How to use snippet as a string?
Hello, can I use the the snippet as string without use python variable?
%%sql --save mysnip --no-execute
SELECT * FROM B
Manually add parentheses - could be this block obtained?
query = %sqlcmd snippets mysnip
query = '"' + query + '"'
This Works
%%sql
SELECT * jdbc('A', {{query}})
But this not
%%sql
SELECT * jdbc('A', "mysnip")
hi, can you expand?
up until this point, this works:
%%sql --save mysnip --no-execute
SELECT * FROM B
query = %sqlcmd snippets mysnip
query = '"' + query + '"'
and this also works:
%%sql
SELECT * jdbc('A', {{query}})
so I guess what you're asking is if you can do this:
%%sql
SELECT * jdbc('A', "mysnip")
and have "mysnip", expanded to the actual query? if that's what you mean, it isn't possible.
I like to have sql code highlighting. But second parameter in jdbc function is (sql) string that not sql highlighted.
One cell without highlighting:
%%sql
SELECT * jdbc('A', "SELECT * FROM B")
To use highlighted SQL, I split to two cells, but it doesnt work.
First
%%sql --save mysnip --no-execute
SELECT * FROM B
And second:
%%sql
SELECT * jdbc('A', "mysnip")
Why I cannot use "mysnip" Or \"mysnip\"?
Any progress?
The team is at capacity, we'd appreciate a PR!