<div style="text-align:left"><font color="#555555" face="Verdana, Arial, Helvetica, sans-serif"><span style="font-size:12px;line-height:18px">We are preparing our data for production, and have a few import procedures to do so. To keep the database organized, we are creating 2 schemas: "public", and "import".</span></font></div>
<div style="text-align:left"><font color="#555555" face="Verdana, Arial, Helvetica, sans-serif"><span style="font-size:12px;line-height:18px"><br></span></font></div><div style="text-align:left"><font color="#555555" face="Verdana, Arial, Helvetica, sans-serif"><div style="font-size:12px;line-height:18px">
CREATE TABLE import.geo_shapes</div><div style="font-size:12px;line-height:18px">(</div><div style="font-size:12px;line-height:18px">  geo_shape_id serial NOT NULL,</div><div style="font-size:12px;line-height:18px">  geocode character varying(9),</div>
<div style="font-size:12px;line-height:18px">  geography import.geography(MultiPolygon,4326),</div><div style="font-size:12px;line-height:18px">  geo_type integer,</div><div style="font-size:12px;line-height:18px">  CONSTRAINT geo_shapes_geo_shape_id_pk PRIMARY KEY (geo_shape_id )</div>
<div style="font-size:12px;line-height:18px">)</div><div style="font-size:12px;line-height:18px"><br></div><div style="font-size:12px;line-height:18px">When the import.geo_shapes table is finished being loaded, I ALTER the table's schema and change it to "public" so it becomes usable to the application.</div>
<div style="font-size:12px;line-height:18px"><br></div><div style="font-size:12px;line-height:18px">The problem I'm having is the geography column is still tied to the "import" namespace, even though the table's schema is "public".</div>
<div style="font-size:12px;line-height:18px"><br></div><div style="font-size:12px;line-height:18px">To work around the problem I'm creating a new column on geo_shapes as "public.geography" and then using this UPDATE to get it to the correct type:</div>
<div style="font-size:12px;line-height:18px"><br></div><div><div><span style="font-size:12px;line-height:18px">ALTER TABLE geo_shapes</span></div><div><span style="font-size:12px;line-height:18px">RENAME COLUMN geography TO geography_temp;</span></div>
<div><span style="font-size:12px;line-height:18px"><br></span></div><div><span style="font-size:12px;line-height:18px">ALTER TABLE geo_shapes</span></div><div><span style="font-size:12px;line-height:18px">ADD COLUMN geography geography(MultiPolygon,4326);</span></div>
<div><span style="font-size:12px;line-height:18px"><br></span></div><div><span style="font-size:12px;line-height:18px">UPDATE geo_shapes</span></div><div><span style="font-size:12px;line-height:18px">SET geography = public.ST_GeogFromWKB(import.ST_AsBinary(geography_temp))</span></div>
<div><span style="font-size:12px;line-height:18px"><br></span></div><div><span style="font-size:12px;line-height:18px">ALTER TABLE geo_shapes</span></div><div><span style="font-size:12px;line-height:18px">DROP COLUMN geography_temp;  </span></div>
</div><div><span style="font-size:12px;line-height:18px"><br></span></div><div><span style="font-size:12px;line-height:18px">Is there a better way to do this? Seems like the ideal thing would be to have the types defined at the database level, but doesn't seem like that is possible.</span></div>
<div><span style="font-size:12px;line-height:18px"><br></span></div></font></div>