From d04f0f466f74e2fb6caab2da259664f5eb02079e Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Tue, 2 Feb 2016 09:25:57 +0000 Subject: [Zurich] SQL script to bulk-update reports from CSV --- bin/zurich/update_report_descriptions.sql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bin/zurich/update_report_descriptions.sql (limited to 'bin') diff --git a/bin/zurich/update_report_descriptions.sql b/bin/zurich/update_report_descriptions.sql new file mode 100644 index 000000000..13616aeac --- /dev/null +++ b/bin/zurich/update_report_descriptions.sql @@ -0,0 +1,23 @@ +-- Zurich would like to update the detail text of a whole bunch +-- of reports on the site. They've provided a CSV file with the report id +-- and the new detail text for the reports in question. +-- This script applies the new details to the database +-- from the file 'report_updates.txt'. This file must be stripped +-- of its header row or errors will occur. +BEGIN; + +CREATE TEMP TABLE report_updates (id int, detail text); + +\copy report_updates FROM 'report_updates.txt' WITH (FORMAT CSV) + +UPDATE problem +SET detail = report_updates.detail +FROM report_updates +WHERE problem.id = report_updates.id +-- Only update a report if its detail field has actually changed: +AND problem.detail != report_updates.detail; + + +DROP TABLE report_updates; + +COMMIT; -- cgit v1.2.3