jupysql icon indicating copy to clipboard operation
jupysql copied to clipboard

How to use snippet as a string?

Open vanheck opened this issue 1 year ago • 4 comments

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")

vanheck avatar Mar 21 '24 16:03 vanheck

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.

edublancas avatar Mar 23 '24 17:03 edublancas

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\"?

vanheck avatar Mar 25 '24 21:03 vanheck

Any progress?

vanheck avatar Oct 31 '24 12:10 vanheck

The team is at capacity, we'd appreciate a PR!

edublancas avatar Oct 31 '24 13:10 edublancas