ipython-sql icon indicating copy to clipboard operation
ipython-sql copied to clipboard

SQL Meta command doesn't work.

Open YousefSaber opened this issue 4 years ago • 4 comments

First I run

%%sql
create table Userpro
(
    email text primary key,
    username text unique not null,
    birthday timestamp not null,
    Home_Adress text not null,
    Phone_No text unique not null,
    password text not null
);

in a Jupyter cell then in the next cell I run

%sql \d Userpro 

gives me this error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-078ee6799747> in <module>
----> 1 get_ipython().run_line_magic('sql', '\\d Userpro')

~/miniconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2325                 kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2326             with self.builtin_trap:
-> 2327                 result = fn(*args, **kwargs)
   2328             return result
   2329 

<decorator-gen-118> in execute(self, line, cell, local_ns)

~/miniconda3/lib/python3.8/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

<decorator-gen-117> in execute(self, line, cell, local_ns)

~/miniconda3/lib/python3.8/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~/miniconda3/lib/python3.8/site-packages/sql/magic.py in execute(self, line, cell, local_ns)
     93 
     94         try:
---> 95             result = sql.run.run(conn, parsed['sql'], self, user_ns)
     96 
     97             if result is not None and not isinstance(result, str) and self.column_local_vars:

~/miniconda3/lib/python3.8/site-packages/sql/run.py in run(conn, sql, config, user_namespace)
    335                 _, cur, headers, _ = pgspecial.execute(
    336                     conn.session.connection.cursor(), statement)[0]
--> 337                 result = FakeResultProxy(cur, headers)
    338             else:
    339                 txt = sqlalchemy.sql.text(statement)

~/miniconda3/lib/python3.8/site-packages/sql/run.py in __init__(self, cursor, headers)
    298 
    299     def __init__(self, cursor, headers):
--> 300         self.fetchall = cursor.fetchall
    301         self.fetchmany = cursor.fetchmany
    302         self.rowcount = cursor.rowcount

AttributeError: 'list' object has no attribute 'fetchall'

help please.

YousefSaber avatar Jan 11 '21 14:01 YousefSaber

I am also getting this.

# Name                    Version                   Build  Channel
ipython-sql               0.3.9           pyhd8ed1ab_1004    conda-forge

It looks like conda-forge is way way behind. https://github.com/catherinedevlin/ipython-sql/blob/master/NEWS.rst

  • 0.4.0
    • Changed most non-SQL commands to argparse arguments (thanks pik)
    • User can specify a creator for connections (thanks pik)
    • Bogus pseudo-SQL command PERSIST removed, replaced with --persist arg
    • Turn off echo of connection information with displaycon in config
    • Consistent support for {} variables (thanks Lucas)
  • 0.4.1
    • Fixed .rst file location in MANIFEST.in
    • Parse SQL comments in first line
    • Bugfixes for DSN, --close, others

youngjoel avatar Nov 14 '22 15:11 youngjoel

Upgrading to 0.4.1 from 0.3.9 doesn't fix the problem.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_2499017/1620114033.py in <module>
----> 1 get_ipython().run_line_magic('sql', '\\d mytablename')

~/anaconda3/lib/python3.9/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2349 
   2350             # Determine stack_depth depending on where run_line_magic() has been called
-> 2351             stack_depth = _stack_depth
   2352             if getattr(fn, magic.MAGIC_NO_VAR_EXPAND_ATTR, False):
   2353                 # magic has opted out of var_expand

~/anaconda3/lib/python3.9/site-packages/decorator.py in fun(*args, **kw)
    230             if not kwsyntax:
    231                 args, kw = fix(args, kw, sig)
--> 232             return caller(func, *(extras + args), **kw)
    233     fun.__name__ = func.__name__
    234     fun.__doc__ = func.__doc__

~/anaconda3/lib/python3.9/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~/anaconda3/lib/python3.9/site-packages/decorator.py in fun(*args, **kw)
    230             if not kwsyntax:
    231                 args, kw = fix(args, kw, sig)
--> 232             return caller(func, *(extras + args), **kw)
    233     fun.__name__ = func.__name__
    234     fun.__doc__ = func.__doc__

~/anaconda3/lib/python3.9/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~/anaconda3/lib/python3.9/site-packages/sql/magic.py in execute(self, line, cell, local_ns)
     93     @argument(
     94         "-l", "--connections", action="store_true", help="list active connections"
---> 95     )
     96     @argument("-x", "--close", type=str, help="close a session by name")
     97     @argument(

~/anaconda3/lib/python3.9/site-packages/sql/run.py in run(conn, sql, config, user_namespace)
    335 _COMMIT_BLACKLIST_DIALECTS = ("athena", "bigquery", "clickhouse", "ingres", "mssql", "teradata", "vertica")
    336 
--> 337 
    338 def _commit(conn, config):
    339     """Issues a commit, if appropriate for current config and dialect"""

~/anaconda3/lib/python3.9/site-packages/sql/run.py in __init__(self, cursor, headers)
    298 
    299 class FakeResultProxy(object):
--> 300     """A fake class that pretends to behave like the ResultProxy from
    301     SqlAlchemy.
    302     """

AttributeError: 'list' object has no attribute 'fetchall'

youngjoel avatar Nov 14 '22 17:11 youngjoel

Duplicate of #114

youngjoel avatar Nov 14 '22 18:11 youngjoel

However forcing the notebook kernel to python3.10 did seem to fix?

youngjoel avatar Nov 14 '22 21:11 youngjoel