X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/06602b4ec0102d89e3c80a966eec1388de71c0f3..56d24085f9b5b2e1d0d0fd5ff8af0c905765ff04:/nominatim/tools/freeze.py diff --git a/nominatim/tools/freeze.py b/nominatim/tools/freeze.py index ce0b5cde..a182fc8b 100644 --- a/nominatim/tools/freeze.py +++ b/nominatim/tools/freeze.py @@ -3,6 +3,8 @@ Functions for removing unnecessary data from the database. """ from pathlib import Path +from psycopg2 import sql as pysql + UPDATE_TABLES = [ 'address_levels', 'gb_postcode', @@ -21,11 +23,11 @@ def drop_update_tables(conn): """ Drop all tables only necessary for updating the database from OSM replication data. """ - - where = ' or '.join(["(tablename LIKE '{}')".format(t) for t in UPDATE_TABLES]) + parts = (pysql.SQL("(tablename LIKE {})").format(pysql.Literal(t)) for t in UPDATE_TABLES) with conn.cursor() as cur: - cur.execute("SELECT tablename FROM pg_tables WHERE " + where) + cur.execute(pysql.SQL("SELECT tablename FROM pg_tables WHERE ") + + pysql.SQL(' or ').join(parts)) tables = [r[0] for r in cur] for table in tables: