I'm using SQLAlchemy to access PostgreSQL database, and I defined the object like this:
class SessionLog(Base):
__tablename__ = 'session_log'
id = Column(Integer, primary_key=True)
recordFile = Column('record_file', String(128))
appSrcPorts = Column('app_src_ports', ARRAY(Integer))
info5 = Column('info5', String(100))
and I select and update the session_log table like this:
session = Session()
sessionLog = session.query(SessionLog).filter_by(id=sessionLogId).first()
sessionLog.appSrcPorts.append(1)
session.merge(sessionLog)
session.commit()
But it is weird the column 'app_src_ports' not update after I called merge() and commit().
And I find a ugly way to make it work, before the append() line, add this:
sessionLog.appSrcPorts = list(sessionLog.appSrcPorts)
Anyone can tell me why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…