X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/101a1f895d25451535f5c186d2ce1f5b7e753e3b..3d58254462289cad257cb96d60b7a24f8e7fc8da:/nominatim/tools/freeze.py?ds=sidebyside diff --git a/nominatim/tools/freeze.py b/nominatim/tools/freeze.py index cc1bf97e..e502c963 100644 --- a/nominatim/tools/freeze.py +++ b/nominatim/tools/freeze.py @@ -1,8 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2022 by the Nominatim developer community. +# For a full list of authors see the git log. """ 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,15 +29,15 @@ 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: - cur.execute('DROP TABLE IF EXISTS "{}" CASCADE'.format(table)) + cur.drop_table(table, cascade=True) conn.commit()