X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/efafa5271957fb54b356ec1c90e8613f14de40d4..27f7c7fd88e588c48c006b459d9912c23b4e13c0:/nominatim/db/connection.py diff --git a/nominatim/db/connection.py b/nominatim/db/connection.py index 1c115207..45bc173d 100644 --- a/nominatim/db/connection.py +++ b/nominatim/db/connection.py @@ -90,6 +90,17 @@ class _Connection(psycopg2.extensions.connection): return num == 1 + def table_has_column(self, table, column): + """ Check if the table 'table' exists and has a column with name 'column'. + """ + with self.cursor() as cur: + has_column = cur.scalar("""SELECT count(*) FROM information_schema.columns + WHERE table_name = %s + and column_name = %s""", + (table, column)) + return has_column > 0 + + def index_exists(self, index, table=None): """ Check that an index with the given name exists in the database. If table is not None then the index must relate to the given