我有一段代码:
def get_summary_data(self):
summary_data = self.page_data.find('table', {'class': 'GroupBox1'})
record = {}
rows = summary_data.findAll('tr')
for row in rows:
fields = row.findAll('td')
for field in fields:
key = field.find(text=True, recursive=False).strip()
value = field.find('strong').text.strip() if field.find('strong') else None
value = value if value else None
if key != '':
record[self.configuration[key]] = value
ins_qry = "INSERT INTO {tablename} ({columns}) VALUES {values};".format(
tablename='rrc_completion_data.summarydata',
columns=', '.join(record.keys()),
values=tuple(record.values())
)
self.engine.execute(ins_qry)
生成的查询如下所示:
INSERT INTO rrc_completion_data.summarydata (Track_No, Status, Operator_Nm, Compl_Type, Field_Nm, Completion_Dt, Lease_Nm, Filing_Purpose, District_No, Well_Type, LeaseNo, County, Well_No, WellBore_Profile, API, WB_Compl_Type, DrilL_Permit_No, SL_Parent_Drill_Permit_No, Field_No, Horiz_Depth_Severance) VALUES ('2928', 'Work in Progress', 'WILLIAMS PROD. GULF COAST, L.P. (924558)', 'New Well', 'NEWARK, EAST (BARNETT SHALE)', '05/17/2010', 'DR. BOB SMITH A NORTH', 'Initial Potential', '09', 'Producing', None, 'DENTON', '10H', 'HORIZONTAL', '42-121-33861', None, '687311', None, '65280200', None);
正如您所看到的,我正试图将none的值用作空值。但会导致以下错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column "none" does not exist
LINE 1: ...A NORTH', 'Initial Potential', '09', 'Producing', None, 'DEN...
我错过了什么?我的目的是在数据库表中不存在空值。
谢谢