@@ -67,10 +67,15 @@ OUTPUTS:
6767DROP TABLE IF EXISTS _init_bis_devdb;
6868
6969WITH applications AS (
70- SELECT
70+ SELECT
7171 * ,
72- ROW_NUMBER() OVER(PARTITION BY jobnumber ORDER BY SUBSTR(dobrundate, 7 , 4 )|| SUBSTR(dobrundate, 1 , 2 )|| SUBSTR(dobrundate, 4 , 2 ) DESC ) as gid,
73- SUBSTR(dobrundate, 7 , 4 )|| SUBSTR(dobrundate, 1 , 2 )|| SUBSTR(dobrundate, 4 , 2 ) as dobrundate
72+ ROW_NUMBER()
73+ OVER (
74+ PARTITION BY jobnumber
75+ ORDER BY SUBSTR(dobrundate, 7 , 4 ) || SUBSTR(dobrundate, 1 , 2 ) || SUBSTR(dobrundate, 4 , 2 ) DESC
76+ )
77+ AS gid,
78+ SUBSTR(dobrundate, 7 , 4 ) || SUBSTR(dobrundate, 1 , 2 ) || SUBSTR(dobrundate, 4 , 2 ) AS dobrundate
7479 FROM dob_jobapplications
7580),
7681
@@ -83,8 +88,8 @@ applications_of_interest AS (
8388 jobtype ~* ' A1|DM|NB' OR (
8489 jobtype = ' A2'
8590 AND sprinkler IS NULL
86- AND lower (jobdescription) LIKE ' %combin%'
87- AND lower (jobdescription) NOT LIKE ' %sprinkler%'
91+ AND LOWER (jobdescription) LIKE ' %combin%'
92+ AND LOWER (jobdescription) NOT LIKE ' %sprinkler%'
8893 )
8994 ) AND gid = 1
9095),
@@ -110,32 +115,32 @@ mapping_and_cleaning AS (
110115
111116 -- removing '.' for existingoccupancy
112117 -- and proposedoccupancy (3 records affected)
113- replace (existingoccupancy, ' .' , ' ' ) AS _occ_initial,
114- replace (proposedoccupancy, ' .' , ' ' ) AS _occ_proposed,
118+ REPLACE (existingoccupancy, ' .' , ' ' ) AS _occ_initial,
119+ REPLACE (proposedoccupancy, ' .' , ' ' ) AS _occ_proposed,
115120
116121 -- set 0 -> null for jobtype = A1 or DM
117122 CASE
118123 WHEN jobtype ~* ' A1|DM'
119- THEN nullif (existingnumstories, ' 0' )::numeric
124+ THEN NULLIF (existingnumstories, ' 0' )::numeric
120125 END AS stories_init,
121126
122127 -- set 0 -> null for jobtype = A1 or NB
123128 CASE
124129 WHEN jobtype ~* ' A1|NB'
125- THEN nullif (proposednumstories, ' 0' )::numeric
130+ THEN NULLIF (proposednumstories, ' 0' )::numeric
126131 END AS stories_prop,
127132
128133 -- set 0 -> null for jobtype = A1 or DM\
129134 CASE
130135 WHEN jobtype ~* ' A1|DM'
131- THEN nullif (existingzoningsqft, ' 0' )::numeric
136+ THEN NULLIF (existingzoningsqft, ' 0' )::numeric
132137 ELSE existingzoningsqft::numeric
133138 END AS zoningsft_init,
134139
135140 -- set 0 -> null for jobtype = A1 or DM
136141 CASE
137142 WHEN jobtype ~* ' A1|DM'
138- THEN nullif (proposedzoningsqft, ' 0' )::numeric
143+ THEN NULLIF (proposedzoningsqft, ' 0' )::numeric
139144 ELSE proposedzoningsqft::numeric
140145 END AS zoningsft_prop,
141146
@@ -171,7 +176,7 @@ mapping_and_cleaning AS (
171176 WHEN landmarked = ' Y' THEN ' Yes'
172177 END AS landmark,
173178
174- ownership_translate (
179+ OWNERSHIP_TRANSLATE (
175180 cityowned,
176181 ownertype,
177182 nonprofit
@@ -185,12 +190,12 @@ mapping_and_cleaning AS (
185190
186191 CASE
187192 WHEN jobtype ~* ' A1|DM'
188- THEN nullif (existingheight, ' 0' )
193+ THEN NULLIF (existingheight, ' 0' )
189194 END::numeric AS height_init,
190195
191196 CASE
192197 WHEN jobtype ~* ' A1|NB'
193- THEN nullif (proposedheight, ' 0' )
198+ THEN NULLIF (proposedheight, ' 0' )
194199 END::numeric AS height_prop,
195200
196201 totalconstructionfloorarea AS constructnsf,
@@ -221,17 +226,17 @@ mapping_and_cleaning AS (
221226 END AS curbcut,
222227
223228 cluster AS tracthomes,
224- regexp_replace (
225- trim (housenumber),
229+ REGEXP_REPLACE (
230+ TRIM (housenumber),
226231 ' (^|)0*' , ' ' , ' '
227232 ) AS address_numbr,
228- trim (streetname) AS address_street,
229- regexp_replace (
230- trim (housenumber),
233+ TRIM (streetname) AS address_street,
234+ REGEXP_REPLACE (
235+ TRIM (housenumber),
231236 ' (^|)0*' , ' ' , ' '
232- ) || ' ' || trim (streetname) AS address,
237+ ) || ' ' || TRIM (streetname) AS address,
233238 bin,
234- left (bin, 1 ) || lpad (block, 5 , ' 0' ) || lpad(right (lot, 4 ), 4 , ' 0' ) AS bbl,
239+ LEFT (bin, 1 ) || LPAD (block, 5 , ' 0' ) || LPAD(RIGHT (lot, 4 ), 4 , ' 0' ) AS bbl,
235240 CASE
236241 WHEN borough ~* ' Manhattan' THEN ' 1'
237242 WHEN borough ~* ' Bronx' THEN ' 2'
@@ -244,7 +249,7 @@ mapping_and_cleaning AS (
244249 buildingclass AS bldg_class,
245250 otherdesc AS desc_other,
246251 specialactionstatus AS x_withdrawal,
247- st_setsrid(st_point (
252+ ST_SETSRID(ST_POINT (
248253 longitude::double precision ,
249254 latitude::double precision
250255 ), 4326 ) AS dob_geom
0 commit comments