X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f6e894a53af83a69f553555cb4a6248d57a58391..d5fc3b5e9992ecd98a12c0f7f726bcb3829c12a4:/nominatim/db/connection.py?ds=inline diff --git a/nominatim/db/connection.py b/nominatim/db/connection.py index 12f5f4e1..ac8d7c85 100644 --- a/nominatim/db/connection.py +++ b/nominatim/db/connection.py @@ -9,7 +9,7 @@ import psycopg2 import psycopg2.extensions import psycopg2.extras -from ..errors import UsageError +from nominatim.errors import UsageError LOG = logging.getLogger() @@ -75,6 +75,17 @@ class _Connection(psycopg2.extensions.connection): return True + def drop_table(self, name, if_exists=True): + """ Drop the table with the given name. + Set `if_exists` to False if a non-existant table should raise + an exception instead of just being ignored. + """ + with self.cursor() as cur: + cur.execute("""DROP TABLE {} "{}" + """.format('IF EXISTS' if if_exists else '', name)) + self.commit() + + def server_version_tuple(self): """ Return the server version as a tuple of (major, minor). Converts correctly for pre-10 and post-10 PostgreSQL versions.