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

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

    
13
SELECT functions.set_col_types('"COUNTY"', ARRAY[
14
  ('.STATECD' , 'integer')
15
, ('.UNITCD'  , 'integer')
16
, ('.COUNTYCD', 'integer')
17
]::functions.col_cast[]);
18

    
19
SELECT functions.create_if_not_exists($$ALTER TABLE "COUNTY" ADD CONSTRAINT "COUNTY.ID"     UNIQUE ("COUNTY.CN")                       $$);
20
SELECT functions.create_if_not_exists($$ALTER TABLE "COUNTY" ADD CONSTRAINT "COUNTY.unique" UNIQUE (".STATECD", ".UNITCD", ".COUNTYCD")$$);
    (1-1/1)