New to Python and SQLquery. I am trying to query an existing table in mssql. First task is displaying what is in the table, the other tasK i also want to do is do an exists() statment to check if the data in the table does exist. These are me code snippets so far:
def dbhandler():
params = urllib.parse.quote_plus(db_string)
engine = db.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
connection = engine.connect()
metadata = db.MetaData()
odfs_tester_history_files = db.Table('odfs_tester_history_files', metadata, autoload=True, autoload_with=engine)
odfs_tester_history = db.Table('odfs_tester_history', metadata, autoload=True, autoload_with=engine)
tables_dict = {'odfs_tester_history_files': {'engine': engine, 'connection': connection, 'table': odfs_tester_history_files}, 'odfs_tester_history': {'engine': engine, 'connection': connection, 'table': odfs_tester_history}}
#return {'engine': engine, 'connection': connection, 'table': odfs_tester_history_files}
return tables_dict
db_instance = dbhandler()
odfs_tabletest_dict = db_instance['odfs_tester_history']
foo_col = db.sql.column('CSV_FILENAME')
sql = db.select(odfs_tabletest_dict['table']).where(odfs_tabletest_dict['odfs_tester_history'].c.foo_col == '06_16_2020_FMGN519.csv')
df = pd.read_sql(sql, odfs_tabletest_dict['connection'])
print(df)
However when I run the code, I get the following error: sqlalchemy.exc.ArgumentError: columns argument to select() must be a Python list or other iterable. How can I fix this? Also how can i use an exists statement to check if the data in question, the .csv file is in the table and just return a true or false value for me to use as duplicate check?