Skip to content
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

How to use snippet as a string? #998

Open
vanheck opened this issue Mar 21, 2024 · 4 comments
Open

How to use snippet as a string? #998

vanheck opened this issue Mar 21, 2024 · 4 comments

Comments

@vanheck
Copy link

vanheck commented Mar 21, 2024

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
Copy link

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
Copy link
Author

vanheck commented Mar 25, 2024

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
Copy link
Author

vanheck commented Oct 31, 2024

Any progress?

@edublancas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants