Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread James Fennell
> However I cannot catch for this error, I can only catch for "sqlalchemy.exc.ProgrammingError". Why is that? James On Wed, Dec 4, 2019 at 6:03 PM Jonathan Vanasco wrote: > > Personally, I would handle the check like this: > > ERRORS_UNDEFINED_TABLE = (psycopg2.errors.UndefinedTable, ) > >

Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Jonathan Vanasco
Personally, I would handle the check like this: ERRORS_UNDEFINED_TABLE = (psycopg2.errors.UndefinedTable, ) try: res = conn.execute(stmt) except sa.exc.ProgrammingError as err: if isinstance(err.orig, ERRORS_UNDEFINED_TABLE): print('Table does not exist') raise This

Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Zsolt Ero
Thanks. So is the following code correct for psycopg2 specific scenario? try: res = conn.execute(stmt) except sa.exc.ProgrammingError as err: if isinstance(err.orig, psycopg2.errors.UndefinedTable): print('Table does not exist') else: raise err -- SQLAlchemy - The

Re: [sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Simon King
Rather than looking at the string representation, you could inspect the "orig" attribute of the SQLAlchemy exception: https://docs.sqlalchemy.org/en/13/core/exceptions.html#sqlalchemy.exc.DBAPIError Simon On Wed, Dec 4, 2019 at 5:52 PM Zsolt Ero wrote: > > My best idea so far is > > if

[sqlalchemy] Re: How to check for table's existance without a separate query

2019-12-04 Thread Zsolt Ero
My best idea so far is if 'psycopg2.errors.UndefinedTable' in str(err) Just to note, I'm looking especially for psycopg2.errors.UndefinedTable, I'm not using any other DB. On Wednesday, 4 December 2019 18:37:02 UTC+1, Zsolt Ero wrote: > > Hi, > > I'm looking for a way to check for a table's