|
1 | 1 | -- Given a CSV of re-scraped cases, update the matching cases in the database
|
2 | 2 | CREATE TEMPORARY TABLE raw_case (
|
3 |
| - ad_damnum text, |
4 |
| - calendar text, |
5 |
| - case_number text, |
6 |
| - case_type text, |
7 |
| - court text, |
8 |
| - division text, |
9 |
| - filing_date text, |
10 |
| - hash text, |
11 |
| - scraped_at text, |
12 |
| - updated_at text |
| 3 | + ad_damnum text, |
| 4 | + calendar text, |
| 5 | + case_number text, |
| 6 | + case_type text, |
| 7 | + court text, |
| 8 | + division text, |
| 9 | + filing_date text, |
| 10 | + hash text, |
| 11 | + scraped_at text, |
| 12 | + updated_at text |
13 | 13 | );
|
14 | 14 |
|
15 |
| -.mode csv |
16 |
| -.import /dev/stdin raw_case |
| 15 | +.mode csv -- noqa |
| 16 | +.import /dev/stdin raw_case -- noqa |
17 | 17 |
|
18 | 18 | -- Update cases that have changed (i.e. their hashes are different)
|
19 | 19 | UPDATE court_case
|
20 |
| -SET calendar = raw_case.calendar, |
21 |
| -filing_date = raw_case.filing_date, |
22 |
| -division = raw_case.division, |
23 |
| -case_type = raw_case.case_type, |
24 |
| -ad_damnum = raw_case.ad_damnum, |
25 |
| -court = raw_case.court, |
26 |
| -hash = raw_case.hash, |
27 |
| -scraped_at = raw_case.scraped_at, |
28 |
| -updated_at = raw_case.scraped_at |
| 20 | +SET |
| 21 | + calendar = raw_case.calendar, |
| 22 | + filing_date = raw_case.filing_date, |
| 23 | + division = raw_case.division, |
| 24 | + case_type = raw_case.case_type, |
| 25 | + ad_damnum = raw_case.ad_damnum, |
| 26 | + court = raw_case.court, |
| 27 | + hash = raw_case.hash, |
| 28 | + scraped_at = raw_case.scraped_at, |
| 29 | + updated_at = raw_case.scraped_at |
29 | 30 | FROM raw_case
|
30 |
| -WHERE court_case.case_number = raw_case.case_number and court_case.hash != raw_case.hash; |
| 31 | +WHERE |
| 32 | + court_case.case_number = raw_case.case_number AND court_case.hash != raw_case.hash; |
31 | 33 |
|
32 | 34 | -- For cases that haven't changed, just update their scraped_at field
|
33 | 35 | UPDATE court_case
|
34 | 36 | SET scraped_at = raw_case.scraped_at
|
35 |
| -from raw_case |
36 |
| -where court_case.case_number = raw_case.case_number and court_case.hash = raw_case.hash; |
| 37 | +FROM raw_case |
| 38 | +WHERE |
| 39 | + court_case.case_number = raw_case.case_number AND court_case.hash = raw_case.hash; |
0 commit comments