diff --git a/Orange/data/sql/backend/postgres.py b/Orange/data/sql/backend/postgres.py index 25bd945ee3a..936835ad8ff 100644 --- a/Orange/data/sql/backend/postgres.py +++ b/Orange/data/sql/backend/postgres.py @@ -4,7 +4,7 @@ from contextlib import contextmanager from time import time -from psycopg2 import Error # pylint: disable=import-error +from psycopg2 import Error, ProgrammingError # pylint: disable=import-error from psycopg2.pool import ThreadedConnectionPool # pylint: disable=import-error from Orange.data import ContinuousVariable, DiscreteVariable, StringVariable, TimeVariable @@ -81,7 +81,7 @@ def execute_sql_query(self, query, params=None): cur.execute(query, params) yield cur log.info("%.2f ms: %s", 1000 * (time() - t), utfquery) - except Error as ex: + except (Error, ProgrammingError) as ex: raise BackendError(str(ex)) from ex finally: connection.commit() diff --git a/Orange/widgets/data/owsql.py b/Orange/widgets/data/owsql.py index 63496d4ce55..86e84cce198 100644 --- a/Orange/widgets/data/owsql.py +++ b/Orange/widgets/data/owsql.py @@ -214,7 +214,6 @@ def get_table(self): what = self.sql = self.sqltext.toPlainText() self.table = "Custom SQL" if self.materialize: - import psycopg2 # pylint: disable=import-error if not self.materialize_table_name: self.Error.connection( "Specify a table name to materialize the query") @@ -229,7 +228,7 @@ def get_table(self): pass with self.backend.execute_sql_query("ANALYZE " + self.materialize_table_name): pass - except (psycopg2.ProgrammingError, BackendError) as ex: + except BackendError as ex: self.Error.connection(str(ex)) return None