Repository navigation
Expand file tree
/
Copy pathinvpat_1.sql
More file actions
198 lines (187 loc) · 4.38 KB
/
Copy pathinvpat_1.sql
File metadata and controls
198 lines (187 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
-- What we want is to be able to parse the weekly patent data
-- and insert it very easily into the existing database. Making
-- this really easy requires using the same schema in the database
-- that is used by the preprocessor.
CREATE TABLE invpat_1(
Firstname TEXT,
Middlename TEXT,
Lastname TEXT,
Street TEXT,
City TEXT,
State TEXT,
Country TEXT,
Zipcode TEXT,
Latitude REAL,
Longitude REAL,
InvSeq INT,
Patent TEXT,
AppYear TEXT,
ApplyYear TEXT,
GYear INT,
AppDate TEXT,
Assignee TEXT,
AsgNum INT,
Class TEXT,
Coauthor TEXT,
Invnum TEXT,
Invnum_N TEXT,
Unique_Record_ID TEXT);
-- Here is where we do the copying to load up the invpat_1 table.
-- Once this is done, we drop the invpat table and recreate it.
INSERT INTO invpat_1(
Firstname,
Middlename,
Lastname,
Street,
City,
State,
Country,
Zipcode,
Latitude,
Longitude,
InvSeq,
Patent,
AppYear,
ApplyYear,
GYear,
AppDate,
Assignee,
AsgNum,
Class,
Coauthor,
Invnum,
Invnum_N,
Unique_Record_ID)
SELECT
Firstname,
Middlename,
Lastname,
Street,
City,
State,
Country,
Zipcode,
Latitude,
Longitude,
InvSeq,
Patent,
AppYear,
ApplyYear,
GYear,
AppDate,
Assignee,
AsgNum,
Class,
Coauthor,
Invnum,
Invnum_N,
Unique_Record_ID
FROM invpat;
-- Now we drop the original table...
drop table invpat;
-- ...because we want to recreate it...
CREATE TABLE invpat(
Firstname TEXT,
Middlename TEXT,
Lastname TEXT,
Street TEXT,
City TEXT,
State TEXT,
Country TEXT,
Zipcode TEXT,
Latitude REAL,
Longitude REAL,
InvSeq INT,
Patent TEXT,
AppYear TEXT,
ApplyYear TEXT,
GYear INT,
AppDate TEXT,
Assignee TEXT,
AsgNum INT,
Class TEXT,
Coauthor TEXT,
Invnum TEXT,
Invnum_N TEXT,
Unique_Record_ID TEXT);
-- Now, let's repopulate the original table with data conforming
-- to the same schema as the patent preprocessor emits.
INSERT INTO invpat(
Firstname,
Middlename,
Lastname,
Street,
City,
State,
Country,
Zipcode,
Latitude,
Longitude,
InvSeq,
Patent,
AppYear,
ApplyYear,
GYear,
AppDate,
Assignee,
AsgNum,
Class,
Coauthor,
Invnum,
Invnum_N,
Unique_Record_ID)
SELECT
Firstname,
Middlename,
Lastname,
Street,
City,
State,
Country,
Zipcode,
Latitude,
Longitude,
InvSeq,
Patent,
AppYear,
ApplyYear,
GYear,
AppDate,
Assignee,
AsgNum,
Class,
Coauthor,
Invnum,
Invnum_N,
Unique_Record_ID
FROM invpat_1;
-- Now we drop all the current indexes...
DROP INDEX IF EXISTS idx_assignee;
DROP INDEX IF EXISTS idx_firstlastname;
DROP INDEX IF EXISTS idx_firstname;
DROP INDEX IF EXISTS idx_invnum;
DROP INDEX IF EXISTS idx_lastname;
DROP INDEX IF EXISTS idx_lower;
DROP INDEX IF EXISTS idx_patent;
DROP INDEX IF EXISTS idx_upper;
DROP INDEX IF EXISTS index_invnum_on_invpat;
DROP INDEX IF EXISTS idx_urid;
-- Add new indexes conforming to preprocessing schema...
-- Make sure this matches the index file in the sql
-- directory. At some point, this should be controlled
-- by a python or ruby script which reads the same file
-- that the preprocessor reads.
CREATE INDEX asg on invpat (Assignee);
CREATE INDEX asg2 on invpat (AsgNum);
CREATE INDEX gyr on invpat (Gyear);
CREATE INDEX iNidx ON invpat (Invnum_N);
CREATE INDEX locc on invpat (City);
CREATE INDEX loccs on invpat (City, State);
CREATE INDEX locs on invpat (State);
CREATE INDEX pdx ON invpat (Patent);
CREATE INDEX pidx ON invpat (Patent, InvSeq);
CREATE INDEX idx_urid ON invpat (Unique_Record_ID);
-- Get rid of the temporary table...
drop table invpat_1;
-- And close with a cleanup...
vacuum;