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 existance. I know I can do it > in 2 queries, once for checking the table and one for running the query, > but I'd prefer to do it in one query with a try-except block. > > What is the best way to do this? I'm using psycopg2 and I see that the > raised error is "psycopg2.errors.UndefinedTable". However I cannot catch > for this error, I can only catch for "sqlalchemy.exc.ProgrammingError". > > How can I catch specifically for psycopg2.errors.UndefinedTable inside > sqlalchemy.exc.ProgrammingError? > > Or is there a better way to check for a table's existance? Since it'll be > in an API I'd prefer to keep the query count low. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/3d103596-199a-43bc-aa96-da30e892a33d%40googlegroups.com.
