0

I have a table in db2 as below:
index--------name---------pass
0----------------A-------------No
1----------------B-------------No
2----------------C-------------No

I need to change it to:
index--------name---------pass
0----------------A-------------Yes
1----------------B-------------Yes
2----------------C-------------Yes

This has to be done with sqlalchemy (pandas) pandas.dataframe.to_sql()

like: df.to_sql('asdad', engine, 'PASDA', if_exists='replace', index=False)

instead of replacing the entire table, i just need change the values in column 'pass' using python preferably without looping(in a one liner).

I need it without creating a temporary table in db and without copying the entire table into a dataframe.

With sqlalchemy: like::

metadata = sa.MetaData(schema='XXXXX')
table = sa.Table('Table', metadata, autoload=True, autoload_with=engine)
query = table.update().values(PASS = 'YES').where(table.Index<5)
results = conn.execute(query)

Im getting an error in where part as Table does not have attribute index, what should i actually give there?

ss301
  • 514
  • 9
  • 22

0 Answers0