I\'m uploading a pandas data frame to a table in Postgres using SQLalchemy and psycopg2. How do I access the psycopg2 error that is within the SQLalchemy error?
try:
df.to_sql(name='sql_table', con=engine, if_exists='append', index=False)
except exc.DBAPIError as ex:
if ex.orig.pgcode == '23502':
print("Data could not be uploaded to sql_table: " + ex.orig.diag.message_primary)
else:
raise