Python 筛选False列值返回True
我有两个表,我正在做一个左连接,其中第二个表有一个位列。过滤器返回该位为False的列。但是,当我稍后在循环中检查该值时,它显示为truePython 筛选False列值返回True,python,python-3.x,sqlalchemy,mariadb,Python,Python 3.x,Sqlalchemy,Mariadb,我有两个表,我正在做一个左连接,其中第二个表有一个位列。过滤器返回该位为False的列。但是,当我稍后在循环中检查该值时,它显示为true from sqlalchemy import create_engine from sqlalchemy.orm import Session from sqlalchemy import Column, String, Integer, Boolean, ForeignKey, or_ from sqlalchemy.ext.declarative imp
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from sqlalchemy import Column, String, Integer, Boolean, ForeignKey, or_
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm.exc import NoResultFound
# from sqlalchemy.exc import DataError
Base = declarative_base()
class BoardGame(Base):
__tablename__ = 'game_detail'
id = Column(Integer, primary_key=True)
name = Column(String)
description = Column(String)
process = relationship('Process', uselist=False, back_populates='game_detail')
def __repr__(self):
return "<BoardGame(id='{}', name='{}', description='{}'".format(
self.id, self.name, self.description
)
class Process(Base):
__tablename__ = 'process'
game_id = Column(Integer, ForeignKey('game_detail.id'), primary_key=True)
description_bigram = Column(Boolean)
game_detail = relationship('BoardGame', back_populates='process')
sa_engine = create_engine('mysql+pymysql://bgg:blahblahblah@localhost:49000/boardgamegeek?charset=utf8mb4', pool_recycle=3600)
session = Session(bind=sa_engine)
# Set the scripts execution range of data
maximum_games_to_process = 1
for game in session.query(BoardGame.id, Process.description_bigram).join(Process, isouter=True).filter(Process.description_bigram.is_(False)).limit(maximum_games_to_process):
print('description_bigram', type(game.description_bigram), game.description_bigram)
print(game)
以下是流程表的创建代码,如HeidiSQL所示
CREATE TABLE `process` (
`game_id` INT(11) NOT NULL,
`description_bigram` BIT(1) NOT NULL,
PRIMARY KEY (`game_id`),
CONSTRAINT `FK__GAME_ID_DESCRIPTION` FOREIGN KEY (`game_id`) REFERENCES `game_detail` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
我看到一些帖子回避了SQLAlchemy关于布尔列和(链接与我的情况类似)的问题。我确信这会起作用,但我有其他程序可以很好地处理位列和表布尔定义,所以我不确定为什么这个程序不起作用。引擎盖下面有什么我可以看的吗
这是SQLAlchemy创建的查询
SELECT game_detail.id AS game_detail_id, process.description_bigram AS process_description_bigram
FROM game_detail LEFT OUTER JOIN process ON game_detail.id = process.game_id
WHERE process.description_bigram IS false
我尝试了一些方法,试图让列注册它的正确值,但结果总是正确的
Python是3.6.5版;SQLAlchemy为1.2.7;10.3.13-MariaDB向我们展示由SQLAlchemy生成的SQL查询。@RickJames我已经用SQLAlchemyQueryIther更改
FALSE
为NULL
或摆脱LEFT
。向我们展示由SQLAlchemy生成的SQL查询。@RickJames我已经用SQLAlchemyQueryIther更改更新了问题FALSE
到NULL
或摆脱左侧
。
CREATE TABLE `process` (
`game_id` INT(11) NOT NULL,
`description_bigram` BIT(1) NOT NULL,
PRIMARY KEY (`game_id`),
CONSTRAINT `FK__GAME_ID_DESCRIPTION` FOREIGN KEY (`game_id`) REFERENCES `game_detail` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
SELECT game_detail.id AS game_detail_id, process.description_bigram AS process_description_bigram
FROM game_detail LEFT OUTER JOIN process ON game_detail.id = process.game_id
WHERE process.description_bigram IS false