[postgis-users] Adding postgis column in COPY command?

Markus Schaber schabi at logix-tt.com
Mon Nov 28 08:55:53 PST 2005


Hi, Rick,

Rick Schumeyer wrote:
> I have a database which does not yet contain a geometry column.  I
> populate the database by creating a text file containing the records
> from a perl script, and then issuing a COPY command.
> I plan on adding a geometry column, but I am not sure the best way to
> get the geometry information in.

You can just use SRID=4711;POINT(5 5) in the COPY command in your
geometry column. The parser for the canonical representation that is
used by COPY FROM and COPY TO (and thus pg_dump and pg_restore, btw) is
capapble to parse this representation for upgrade compatibility with
PostGIS 0.X.

You can also leave off the SRID=4711; part, and you can use (E)WKB
instead of (E)WKT.

As the geometry representations don't contain critical characters (tabs
etc), no quoting is needed. Empty geometries can be represented as
GEOMETRYCOLLECTION(EMPTY) or as \N (for sql NULL values) - just use
whichever better fits to your needs.

Markus



More information about the postgis-users mailing list