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 |
8184
|
aaronmk
|
SELECT set_col_types('"COND"', ARRAY[
|
9 |
10054
|
aaronmk
|
('*STATECD', 'integer')
|
10 |
|
|
, ('*UNITCD', 'integer')
|
11 |
|
|
, ('*COUNTYCD', 'integer')
|
12 |
8172
|
aaronmk
|
, ('locationName', 'integer')
|
13 |
10054
|
aaronmk
|
, ('*INVYR', 'integer')
|
14 |
8172
|
aaronmk
|
, ('authorEventCode', 'integer')
|
15 |
8184
|
aaronmk
|
]::col_cast[]);
|
16 |
8110
|
aaronmk
|
|
17 |
8192
|
aaronmk
|
SELECT mk_derived_col(('"COND"', 'oldGrowth'), $$
|
18 |
8100
|
aaronmk
|
(
|
19 |
10054
|
aaronmk
|
"*COND-STDAGE"::integer>80
|
20 |
|
|
AND ("*COND-TRTCD1"='0' OR "*COND-TRTCD1" IS NULL)
|
21 |
|
|
AND (("*COND-DSTRBCD1"<>'30' AND "*COND-DSTRBCD1"<>'31' AND "*COND-DSTRBCD1"<>'32' AND "*COND-DSTRBCD1"<>'80') OR "*COND-DSTRBCD1" IS NULL)
|
22 |
|
|
AND ("*COND-STUMP_CD_PNWRS"='N' OR "*COND-STUMP_CD_PNWRS" IS NULL)
|
23 |
|
|
AND "*COND-HARVEST_TYPE1_SRS" IS NULL
|
24 |
|
|
AND "*COND-PRESNFCD" IS NULL
|
25 |
|
|
AND ("*COND-STDORGCD"='0' OR "*COND-STDORGCD" IS NULL)
|
26 |
8100
|
aaronmk
|
)
|
27 |
10054
|
aaronmk
|
OR "*COND-STND_COND_CD_PNWRS"='7'
|
28 |
8100
|
aaronmk
|
$$);
|
29 |
|
|
|
30 |
10054
|
aaronmk
|
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.ID" UNIQUE ("*COND-CN")$$);
|
31 |
|
|
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.unique" UNIQUE ("*STATECD", "*UNITCD", "*COUNTYCD", "locationName", "*INVYR", "authorEventCode")$$);
|
32 |
8184
|
aaronmk
|
SELECT cluster_once('"COND"', '"COND.unique"');
|
33 |
8208
|
aaronmk
|
EOF
|
34 |
|
|
mk_derived
|