Project

General

Profile

1 8163 aaronmk
#!/bin/bash
2
# :mode=transact-sql:
3
cd "$(dirname "$0")"
4
. ../../../lib/import.sh
5
6 8164 aaronmk
map_table
7 8163 aaronmk
psql <<'EOF'
8 8136 aaronmk
SELECT functions.set_col_types('"COND"', ARRAY[
9 8110 aaronmk
  ('.STATECD' , 'integer')
10
, ('.UNITCD'  , 'integer')
11
, ('.COUNTYCD', 'integer')
12
, ('.PLOT'    , 'integer')
13
, ('.INVYR'   , 'integer')
14
, ('.CONDID'  , 'integer')
15
]::functions.col_cast[]);
16
17 8100 aaronmk
SELECT functions.create_if_not_exists($$
18 8101 aaronmk
ALTER TABLE "COND" ADD   COLUMN "COND.oldgrowth"      boolean;
19
ALTER TABLE "COND" ALTER COLUMN "COND.oldgrowth" TYPE boolean USING
20 8100 aaronmk
(
21 8162 aaronmk
    "COND.STDAGE"::integer>80
22 8100 aaronmk
    AND ("COND.TRTCD1"='0' OR "COND.TRTCD1" IS NULL)
23
    AND (("COND.DSTRBCD1"<>'30' AND "COND.DSTRBCD1"<>'31' AND "COND.DSTRBCD1"<>'32' AND "COND.DSTRBCD1"<>'80') OR "COND.DSTRBCD1" IS NULL)
24
    AND ("COND.STUMP_CD_PNWRS"='N' OR "COND.STUMP_CD_PNWRS" IS NULL)
25
    AND "COND.HARVEST_TYPE1_SRS" IS NULL
26
    AND "COND.PRESNFCD" IS NULL
27
    AND ("COND.STDORGCD"='0' OR "COND.STDORGCD" IS NULL)
28
)
29
OR "COND.STND_COND_CD_PNWRS"='7'
30
;
31
$$);
32
33 8130 aaronmk
SELECT functions.create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.ID"     UNIQUE ("COND.CN")                                                       $$);
34 8098 aaronmk
SELECT functions.create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.unique" UNIQUE (".STATECD", ".UNITCD", ".COUNTYCD", ".PLOT", ".INVYR", ".CONDID")$$);
35 8136 aaronmk
SELECT functions.cluster_once('"COND"', '"COND.unique"');