Project

General

Profile

1 8093 aaronmk
SELECT functions.to_global_col_names(:table_str);
2
3 8098 aaronmk
SELECT functions.rename_if_exists($$ALTER TABLE "COND" RENAME "COND.STATECD"  TO ".STATECD" $$);
4
SELECT functions.rename_if_exists($$ALTER TABLE "COND" RENAME "COND.UNITCD"   TO ".UNITCD"  $$);
5
SELECT functions.rename_if_exists($$ALTER TABLE "COND" RENAME "COND.COUNTYCD" TO ".COUNTYCD"$$);
6
SELECT functions.rename_if_exists($$ALTER TABLE "COND" RENAME "COND.PLOT"     TO ".PLOT"    $$);
7
SELECT functions.rename_if_exists($$ALTER TABLE "COND" RENAME "COND.INVYR"    TO ".INVYR"   $$);
8
SELECT functions.rename_if_exists($$ALTER TABLE "COND" RENAME "COND.CONDID"   TO ".CONDID"  $$);
9
10 8110 aaronmk
SELECT functions.set_col_types(:table_str, ARRAY[
11
  ('.STATECD' , 'integer')
12
, ('.UNITCD'  , 'integer')
13
, ('.COUNTYCD', 'integer')
14
, ('.PLOT'    , 'integer')
15
, ('.INVYR'   , 'integer')
16
, ('.CONDID'  , 'integer')
17
]::functions.col_cast[]);
18
19 8100 aaronmk
SELECT functions.create_if_not_exists($$
20 8101 aaronmk
ALTER TABLE "COND" ADD   COLUMN "COND.oldgrowth"      boolean;
21
ALTER TABLE "COND" ALTER COLUMN "COND.oldgrowth" TYPE boolean USING
22 8100 aaronmk
(
23
    "COND.STDAGE"::integer>80
24
    AND ("COND.TRTCD1"='0' OR "COND.TRTCD1" IS NULL)
25
    AND (("COND.DSTRBCD1"<>'30' AND "COND.DSTRBCD1"<>'31' AND "COND.DSTRBCD1"<>'32' AND "COND.DSTRBCD1"<>'80') OR "COND.DSTRBCD1" IS NULL)
26
    AND ("COND.STUMP_CD_PNWRS"='N' OR "COND.STUMP_CD_PNWRS" IS NULL)
27
    AND "COND.HARVEST_TYPE1_SRS" IS NULL
28
    AND "COND.PRESNFCD" IS NULL
29
    AND ("COND.STDORGCD"='0' OR "COND.STDORGCD" IS NULL)
30
)
31
OR "COND.STND_COND_CD_PNWRS"='7'
32
;
33
$$);
34
35 8098 aaronmk
SELECT functions.create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.unique" UNIQUE (".STATECD", ".UNITCD", ".COUNTYCD", ".PLOT", ".INVYR", ".CONDID")$$);
36 8111 aaronmk
SELECT functions.cluster_once(:table_str, '"COND.unique"');