-
Notifications
You must be signed in to change notification settings - Fork 78
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
some duckdb sql cannot run in jupysql #172
Comments
Ok, so the problem with the first example is that We're fixing this in #93 and for the second example: I couldn't reproduce it (see my output below). I got a "Table with name v_ddl does not exist!" error, which makes sense. But you're getting "invalid syntax", which means that your Python session is interpreting the SQL code as Python; maybe you have some extra line breaks? full session below: first example%load_ext sql %sql duckdb:// %sql create table test_table(sqlstr text); Console output (1/2): * duckdb://
Done. Console output (2/2): %%sql
insert into test_table values ($$create table t(id int)
,code text$$) Console output (1/1): * duckdb://
(duckdb.ParserException) Parser Error: syntax error at or near "create"
LINE 1: insert into test_table values ($create table t(id int)
^
[SQL: insert into test_table values ($create table t(id int)
,code text$$)]
(Background on this error at: https://sqlalche.me/e/14/f405) second example%%sql
select regexp_split_to_array(a.parts,','),regexp_split_to_array(b.parts,',')
from v_ddl a
inner join v_ddl2 b on a.word3=b.word3 and a.sqlstr<>b.sqlstr Console output (1/1): * duckdb://
(duckdb.CatalogException) Catalog Error: Table with name v_ddl does not exist!
Did you mean "pg_am"?
[SQL: select regexp_split_to_array(a.parts,','),regexp_split_to_array(b.parts,',')
from v_ddl a
inner join v_ddl2 b on a.word3=b.word3 and a.sqlstr<>b.sqlstr]
(Background on this error at: https://sqlalche.me/e/14/f405) |
here is the whole test data:
then:
In jupysql error, but in cli it's OK! |
can you share the .py script (the one that you have in the screenshot)? you can remove stuff if there's sensitive info there. |
issue.py.txt |
I see what the problem is! You cannot add comments before the cell magic. This will break: # %%
# stuff
%%sql
create table ddl (sqlstr text);
create table ddl2 (sqlstr text); because Python will interpret the line after the You can create it in a separate cell: # %% [markdown]
# some comment
# %%
# stuff
%%sql
create table ddl (sqlstr text);
create table ddl2 (sqlstr text); Or use a SQL-style comment after the cell magic: # %%
%%sql
-- stuff
create table ddl (sqlstr text);
create table ddl2 (sqlstr text); |
Parser Error: syntax error at or near "create"
LINE 1: insert into test_table values ($create table t(id int
BUT, leave a blank between $$ and create, will OK
raise ERROR:
BUT, this sql have no prolem in duckdb cli or in python.
The text was updated successfully, but these errors were encountered: