Project

General

Profile

1
SELECT util.search_path_append('util');
2

    
3
SELECT set_col_types('"COND"', ARRAY[
4
  ('*STATECD', 'integer')
5
, ('*UNITCD', 'integer')
6
, ('*COUNTYCD', 'integer')
7
, ('locationName', 'integer')
8
, ('*INVYR', 'integer')
9
, ('authorEventCode', 'integer')
10
]::col_cast[]);
11

    
12
SELECT mk_derived_col(('"COND"', 'oldGrowth'), $$
13
-- created by Brad
14
-- modified from sftp://nimoy.nceas.ucsb.edu/home/boyle/bien2/geoscrub/fia/flag_fia_oldGrowth.sql
15
(
16
    "*COND--STDAGE"::integer>80
17
    AND ("*COND--TRTCD1"='0' OR "*COND--TRTCD1" IS NULL)
18
    AND (("*COND--DSTRBCD1"<>'30' AND "*COND--DSTRBCD1"<>'31' AND "*COND--DSTRBCD1"<>'32' AND "*COND--DSTRBCD1"<>'80') OR "*COND--DSTRBCD1" IS NULL)
19
    AND ("*COND--STUMP_CD_PNWRS"='N' OR "*COND--STUMP_CD_PNWRS" IS NULL)
20
    AND "*COND--HARVEST_TYPE1_SRS" IS NULL
21
    AND "*COND--PRESNFCD" IS NULL
22
    AND ("*COND--STDORGCD"='0' OR "*COND--STDORGCD" IS NULL)
23
)
24
OR "*COND--STND_COND_CD_PNWRS"='7'
25
$$);
26

    
27
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.ID"     UNIQUE ("*COND--CN")$$);
28
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.unique" UNIQUE ("*STATECD", "*UNITCD", "*COUNTYCD", "locationName", "*INVYR", "authorEventCode")$$);
29
SELECT cluster_once('"COND"', '"COND.unique"');
(7-7/10)