[postgis-users] pgsql2shp syntax - sentence construction

Stephen Woodbridge woodbri at swoodbridge.com
Mon Jun 2 18:16:59 PDT 2008

SenTnel wrote:
> Hi! Im working with postgres and geoserver but im just not good at sql
> statements, none the less in construction sentences in postgres, and I would
> like to create a shapefile from a table in postgres and don't want to make a
> costly mistake, so if you help me achieve this using pgsql2shp: 
> database name: mydatabase
> schema: myschema
> table: mytable
> shapefile to be created: updatedshp
> database user: postgres
> password: any
> can you help me with the syntax to achieve the shapefile containing all of
> the data (and geom) in such table?
> Thanks !


pgsql2shp is not a SQL statement it is a command line tool:

woodbri at carto:~$ pgsql2shp
RCSID: $Id: pgsql2shp.c,v 1.82 2006/01/16 10:42:57 strk Exp $
USAGE: pgsql2shp [<options>] <database> [<schema>.]<table>
        pgsql2shp [<options>] <database> <query>

   -f <filename>  Use this option to specify the name of the file
      to create.
   -h <host>  Allows you to specify connection to a database on a
      machine other than the default.
   -p <port>  Allows you to specify a database port other than the default.
   -P <password>  Connect to the database with the specified password.
   -u <user>  Connect to the database as the specified user.
   -g <geometry_column> Specify the geometry column to be exported.
   -b Use a binary cursor.
   -r Raw mode. Do not assume table has been created by
      the loader. This would not unescape attribute names
      and will not skip the 'gid' attribute.
   -k Keep postgresql identifiers case.

So you might use it like:

> pgsql2shp -f updatedshp.shp -h localhost -u postgres mydatabase myschema.mytable

Have fun,
   -Steve W

More information about the postgis-users mailing list