0

I have a weird problem with querying for strings using Oracle 11g backend for SQLAlchemy. First, class definition (for Oracle, for Postgres it is the same minus Sequence):

class Item(Base):
    __tablename__ = 'item'
    id = Column(Integer, Sequence('id_seq'), primary_key=True)
    ...
    review = Column(Unicode(2000), index=True)

Basic querying works without a problem with Postgres backend:

In [1]: len(DBSession.query(Item).filter(Item.review != '').limit(100).all())
Out[1]: 100

However, with Oracle 11g:

In [31]: len(DBSession.query(Item).filter(Item.review != '').limit(100).all())
Out[31]: 0

Filtering by empty Unicode string does not work either in Oracle:

In [32]: len(DBSession.query(Item).filter(Item.review != u'').limit(100).all())
Out[32]: 0

Why something so basic does not work with Oracle? And how can I fix that?

1 Answer 1

2

This has nothing to do with SQLAlchemy. Oracle treats empty string == null.

See: Oracle treats an empty string as null

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.