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('"PLOT"');
8

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

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

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