diff options
author | Dave Arter <davea@mysociety.org> | 2016-02-02 09:25:57 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-04-07 16:29:44 +0100 |
commit | d04f0f466f74e2fb6caab2da259664f5eb02079e (patch) | |
tree | f21f23e8678a82339c9e008377fcf4fc613a35ba /bin/zurich | |
parent | dc5e30296d78b3171188acaef8bca1ae4e7b4596 (diff) |
[Zurich] SQL script to bulk-update reports from CSV
Diffstat (limited to 'bin/zurich')
-rw-r--r-- | bin/zurich/update_report_descriptions.sql | 23 |
1 files changed, 23 insertions, 0 deletions
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; |