Project

General

Profile

1
#!/bin/bash
2
# :mode=transact-sql:
3
cd "$(dirname "$0")"
4
. ../../../lib/import.sh
5

    
6
psql <<'EOF'
7
SELECT functions.to_global_col_names('"SUBPLOT"');
8

    
9
SELECT functions.rename_if_exists($$ALTER TABLE "SUBPLOT" RENAME "SUBPLOT.STATECD"  TO ".STATECD" $$);
10
SELECT functions.rename_if_exists($$ALTER TABLE "SUBPLOT" RENAME "SUBPLOT.UNITCD"   TO ".UNITCD"  $$);
11
SELECT functions.rename_if_exists($$ALTER TABLE "SUBPLOT" RENAME "SUBPLOT.COUNTYCD" TO ".COUNTYCD"$$);
12
SELECT functions.rename_if_exists($$ALTER TABLE "SUBPLOT" RENAME "SUBPLOT.PLOT"     TO ".PLOT"    $$);
13
SELECT functions.rename_if_exists($$ALTER TABLE "SUBPLOT" RENAME "SUBPLOT.INVYR"    TO ".INVYR"   $$);
14
SELECT functions.rename_if_exists($$ALTER TABLE "SUBPLOT" RENAME "SUBPLOT.SUBP"     TO ".SUBP"    $$);
15

    
16
SELECT functions.set_col_types('"SUBPLOT"', ARRAY[
17
  ('.STATECD' , 'integer')
18
, ('.UNITCD'  , 'integer')
19
, ('.COUNTYCD', 'integer')
20
, ('.PLOT'    , 'integer')
21
, ('.INVYR'   , 'integer')
22
, ('.SUBP'    , 'integer')
23
]::functions.col_cast[]);
24

    
25
SELECT functions.create_if_not_exists($$ALTER TABLE "SUBPLOT" ADD CONSTRAINT "SUBPLOT.ID"     UNIQUE ("SUBPLOT.CN")                                                  $$);
26
SELECT functions.create_if_not_exists($$ALTER TABLE "SUBPLOT" ADD CONSTRAINT "SUBPLOT.unique" UNIQUE (".STATECD", ".UNITCD", ".COUNTYCD", ".PLOT", ".INVYR", ".SUBP")$$);
27
SELECT functions.cluster_once('"SUBPLOT"', '"SUBPLOT.unique"');
    (1-1/1)