SELECT functions.to_global_col_names(:table_str);

SELECT functions.rename_if_exists($$ALTER TABLE "PLOT" RENAME "PLOT.STATECD"  TO ".STATECD" $$);
SELECT functions.rename_if_exists($$ALTER TABLE "PLOT" RENAME "PLOT.UNITCD"   TO ".UNITCD"  $$);
SELECT functions.rename_if_exists($$ALTER TABLE "PLOT" RENAME "PLOT.COUNTYCD" TO ".COUNTYCD"$$);
SELECT functions.rename_if_exists($$ALTER TABLE "PLOT" RENAME "PLOT.PLOT"     TO ".PLOT"    $$);
SELECT functions.rename_if_exists($$ALTER TABLE "PLOT" RENAME "PLOT.INVYR"    TO ".INVYR"   $$);

SELECT functions.set_col_types(:table_str, ARRAY[
  ('.STATECD' , 'integer')
, ('.UNITCD'  , 'integer')
, ('.COUNTYCD', 'integer')
, ('.PLOT'    , 'integer')
, ('.INVYR'   , 'integer')
]::functions.col_cast[]);

SELECT functions.create_if_not_exists($$ALTER TABLE "PLOT" ADD CONSTRAINT "PLOT.unique" UNIQUE (".STATECD", ".UNITCD", ".COUNTYCD", ".PLOT", ".INVYR")$$);
SELECT functions.cluster_once(:table_str, '"PLOT.unique"');
