comparison src/pgsql_storage.py @ 402:724e39d596a9

psql: use a set for categories, to avoid duplicates (and constraint failure)
author Goffi <goffi@goffi.org>
date Thu, 23 May 2019 08:58:29 +0200
parents 728b08c0d000
children 1dc606612405
comparison
equal deleted inserted replaced
401:907b10480394 402:724e39d596a9
956 # TODO: handle canonical form 956 # TODO: handle canonical form
957 if update: 957 if update:
958 cursor.execute("""DELETE FROM item_categories 958 cursor.execute("""DELETE FROM item_categories
959 WHERE item_id=%s""", (item_id,)) 959 WHERE item_id=%s""", (item_id,))
960 960
961 for category in categories: 961 # we use a set to avoid duplicates
962 for category in set(categories):
962 cursor.execute("""INSERT INTO item_categories (item_id, category) 963 cursor.execute("""INSERT INTO item_categories (item_id, category)
963 VALUES (%s, %s)""", (item_id, category)) 964 VALUES (%s, %s)""", (item_id, category))
964 965
965 def removeItems(self, itemIdentifiers): 966 def removeItems(self, itemIdentifiers):
966 return self.dbpool.runInteraction(self._removeItems, itemIdentifiers) 967 return self.dbpool.runInteraction(self._removeItems, itemIdentifiers)