ploomber / jupysql

Better SQL in Jupyter. 📊
https://jupysql.ploomber.io
Apache License 2.0
719 stars 76 forks source link

How to use snippet as a string? #998

Open vanheck opened 7 months ago

vanheck commented 7 months ago

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")
edublancas commented 7 months ago

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.

vanheck commented 7 months ago

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 commented 5 days ago

Any progress?

edublancas commented 5 days ago

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