我正在尝试编写一个从api调用中获取json对象的程序,然后将其加载到数据库中。当我编译AttributeError: 'TextClause' object has no attribute 'implicit_returning'
或尝试自己执行它时,sqlalchemy不断抛出错误stmt
。
def load_results(self):
connect = self.engine.connect()
for ru in self.json_ru:
counties = ru['counties']
for county in counties:
transaction = connect.begin()
params = {"reportingunitName": ru['reportingunitName'],
"geoCode": ru['geocode'],
"townsTotal": ru['towns'],
"townsReporting": ru['townsReporting'],
"cableName": county['cableName'],
"unitCount": county['unitCount']
}
stmt = expression.insert('{}.raw_feed'.format(self.state)).values(params)
compiled_stmt = stmt.compile(self.engine)
connect.execute(compiled_stmt)
transaction.commit()
在我进行查询之前,我只是提供了connect.execute,但是作为值进入的字符串被读作列名,所以我尝试了上面的代码。也使用Postgres风味。