From c85e18853151005581da5e6877497337fec3d579 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Mon, 9 Jan 2023 22:17:15 -0600 Subject: [PATCH] column for count per label --- pgutil.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pgutil.py b/pgutil.py index 4875400..f63a03a 100644 --- a/pgutil.py +++ b/pgutil.py @@ -25,7 +25,8 @@ class PGUTIL: create_label_table = """ CREATE TABLE IF NOT EXISTS label ( id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - name varchar UNIQUE + name varchar UNIQUE, + photocount INT ); """ @@ -78,8 +79,18 @@ class PGUTIL: ); """ + update_label_count = """ + UPDATE label + SET photocount = ( + SELECT COUNT(*) FROM photo + WHERE guesslabel = %s + ) + WHERE name = %s + """ + try: cur.execute(insert_label, [guesslabel]) cur.execute(insert_photo, [filename, guesslabel, matchstrength, guesslabel]) + cur.execute(update_label_count, [guesslabel, guesslabel]) except psycopg2.Error: raise Exception("Problem inserting data for photo " + analysis['filename']) \ No newline at end of file