sql alchemy中的Json字段被截断

zed5wv10  于 2023-01-14  发布在  其他
关注(0)|答案(1)|浏览(122)

我从postgres数据库中获取数据,但是数据被截断了。对于VARCHAR,我知道可以设置最大大小,但是JSON也可以这样做吗,或者有其他方法吗?
以下是我的请求:

robot_id_cast = cast(RobotData.data.op("->>")("id"), String)
robot_camera_cast = cast(RobotData.data.op("->>")(self.camera_name), JSON)

# Get the last upload time for this robot and this camera
subquery_last_upload = (
    select([func.max(RobotData.time).label("last_upload")])
            .where(robot_id_cast == self.robot_id)
            .where(robot_camera_cast != None)
        ).alias("subquery_last_upload")

main_query = (
    select(
    [subquery_last_upload.c.last_upload,RobotData.data.op("->")(self.camera_name).label(self.camera_name),])
            .where(RobotData.time == subquery_last_upload.c.last_upload)
            .where(robot_id_cast == self.robot_id)
            .where(robot_camera_cast != None)
        )

问题出在此选定零件RobotData.data.op("->")(self.camera_name).label(self.camera_name)
这是我的table

class RobotData(PGBase):
    __tablename__ = "wr_table"

    time = Column(DateTime, nullable=False, primary_key=True)
    data = Column(JSON, nullable=False)

编辑:我的JSON是429个字符

相关问题