Project

General

Profile

1 10084 aaronmk
SELECT util.search_path_append('util');
2 8163 aaronmk
3 8184 aaronmk
SELECT set_col_types('"COND"', ARRAY[
4 10054 aaronmk
  ('*STATECD', 'integer')
5
, ('*UNITCD', 'integer')
6
, ('*COUNTYCD', 'integer')
7 8172 aaronmk
, ('locationName', 'integer')
8 10054 aaronmk
, ('*INVYR', 'integer')
9 8172 aaronmk
, ('authorEventCode', 'integer')
10 8184 aaronmk
]::col_cast[]);
11 8110 aaronmk
12 8192 aaronmk
SELECT mk_derived_col(('"COND"', 'oldGrowth'), $$
13 11843 aaronmk
-- created by Brad
14
-- modified from sftp://nimoy.nceas.ucsb.edu/home/boyle/bien2/geoscrub/fia/flag_fia_oldGrowth.sql
15 8100 aaronmk
(
16 10947 aaronmk
    "*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 8100 aaronmk
)
24 10947 aaronmk
OR "*COND--STND_COND_CD_PNWRS"='7'
25 8100 aaronmk
$$);
26
27 10947 aaronmk
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.ID"     UNIQUE ("*COND--CN")$$);
28 10054 aaronmk
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.unique" UNIQUE ("*STATECD", "*UNITCD", "*COUNTYCD", "locationName", "*INVYR", "authorEventCode")$$);
29 8184 aaronmk
SELECT cluster_once('"COND"', '"COND.unique"');