【问题标题】:Filtering for empty string in SQLAlchemy + Oracle在 SQLAlchemy + Oracle 中过滤空字符串
【发布时间】:2016-10-10 08:19:21
【问题描述】:

我在使用 Oracle 11g 后端的 SQLAlchemy 查询字符串时遇到了一个奇怪的问题。首先,类定义(对于Oracle,对于Postgres 相同减去Sequence):

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

使用 Postgres 后端进行基本查询没有问题:

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

但是,对于 Oracle 11g:

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

空 Unicode 字符串过滤在 Oracle 中也不起作用:

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

为什么这么基本的东西不能与 Oracle 一起使用?我该如何解决这个问题?

【问题讨论】:

    标签: python oracle postgresql oracle11g sqlalchemy


    【解决方案1】:

    这与 SQLAlchemy 无关。 Oracle 处理空字符串 == null。

    见:Oracle treats an empty string as null

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多