Sorry, I meant NCLOB, not NVARCHAR.

2014-09-30 16:57 GMT-03:00 Mariano Mara <mariano.m...@gmail.com>:

> Hi there. I have some code that works ok in PG and now I need to make it
> work with Oracle, however I am hitting this error with NVARCHAR and I am
> not sure how to handle it.
>
> First a small code in order you can reproduce it (as you can see "name"
> has been defined as UnicodeText):
>
> from sqlalchemy import create_engine, Integer, UnicodeText, Column, func
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import sessionmaker
> engine = create_engine('oracle://scott:tiger@localhost:1521/xe',
> echo=True)
> Base = declarative_base()
> class User(Base):
>     __tablename__ = 'users'
>     id = Column(Integer, primary_key=True)
>     name = Column(UnicodeText)
> Base.metadata.create_all(engine)
> Session = sessionmaker(bind=engine)
> session = Session()
> qry = session.query(func.count('1'), User.name).group_by(User.name)
> print(qry.all())
>
> but each time I get to the actually execution of the query I hit the same
> error (see below, it is related to the use of an UnicodeText field) and I
> wonder if there is a way to avoid the issue transparently.
>
> TIA,
> Mariano
>
> 2014-09-30 16:48:12,028 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
> 2014-09-30 16:48:12,029 INFO sqlalchemy.engine.base.Engine SELECT
> count(:param_1) AS count_1, users.name AS users_name
> FROM users GROUP BY users.name
> 2014-09-30 16:48:12,030 INFO sqlalchemy.engine.base.Engine {'param_1': '1'}
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py",
> line 2300, in all
>     return list(self)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py",
> line 2412, in __iter__
>     return self._execute_and_instances(context)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py",
> line 2427, in _execute_and_instances
>     result = conn.execute(querycontext.statement, self._params)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py",
> line 729, in execute
>     return meth(self, multiparams, params)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/sql/elements.py",
> line 321, in _execute_on_connection
>     return connection._execute_clauseelement(self, multiparams, params)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py",
> line 826, in _execute_clauseelement
>     compiled_sql, distilled_params
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py",
> line 958, in _execute_context
>     context)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py",
> line 1160, in _handle_dbapi_exception
>     exc_info
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/util/compat.py",
> line 199, in raise_from_cause
>     reraise(type(exception), exception, tb=exc_tb)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py",
> line 951, in _execute_context
>     context)
>   File
> "/home/mariano/Code/env/local/lib/python2.7/site-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/default.py",
> line 436, in do_execute
>     cursor.execute(statement, parameters)
> sqlalchemy.exc.DatabaseError: (DatabaseError) ORA-00932: inconsistent
> datatypes: expected - got NCLOB
>  'SELECT count(:param_1) AS count_1, users.name AS users_name \nFROM
> users GROUP BY users.name' {'param_1': '1'}
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to