.TH grass-pg 1grass "" "GRASS 6.4.2" "Grass User's Manual" .SH NAME grass-pg - PostgreSQL driver PostgreSQL driver PostgreSQL driver in GRASS The driver name is 'pg'. .SH Creating a PostgreSQL database A new database is created with 'createdb', see the PostgreSQL manual for details. .SH Connecting GRASS to PostgreSQL \fC .DS .br # example for connecting to a PostgreSQL server: .br db.connect driver=pg database="host=myserver.osgeo.org,dbname=mydb" .br # password is asked interactively if not specified: .br db.login user=myname [pass=secret] .br db.connect -p .br db.tables -p .br .DE \fR .SH Supported SQL commands All SQL commands supported by PostgreSQL. It's not possible to use C-like escapes (with backslash like \(rsn etc) within SQL syntax. .SH Operators available in conditions All SQL operators supported by PostgreSQL. .SH Adding an unique ID column Import vector module require an unique ID column which can be generated as follows in a PostgreSQL table: \fC .DS .br echo " .br ALTER TABLE mytable ADD ID integer; .br CREATE SEQUENCE mytable_seq; .br UPDATE mytabe SET ID = nextval('mytable_seq'); .br DROP SEQUENCE mytable_seq; .br \(dq | db.execute .br .DE \fR .SH Attribute Converters CSV import into PostgreSQL: \fC .DS .br \(rsh copy .br COPY t1 FROM 'filename' USING DELIMITERS ','; .br .DE \fR pg2xbase: DBF to PostgreSQL converter. .br .SH Geometry import from PostgreSQL table \fIv.in.db\fR creates a new vector (points) map from a database table containing coordinates. See here for examples. .SH PostGIS: PostgreSQL with vector geometry PostGIS: adds geographic object support to PostgreSQL. .SS Example: Import from PostGIS In an existing PostGIS database, create the following table: \fC .DS .br CREATE TABLE test .br ( .br id serial NOT NULL, .br mytime timestamp DEFAULT now(), .br text varchar, .br wkb_geometry geometry, .br CONSTRAINT test_pkey PRIMARY KEY (id) .br ) WITHOUT OIDS; .br .br # insert value .br INSERT INTO test (text, wkb_geometry) .br VALUES ('Name',geometryFromText('POLYGON((600000 200000,650000 .br 200000,650000 250000,600000 250000,600000 200000))',-1)); .br .br # register geometry column .br select AddGeometryColumn ('postgis', 'test', 'geometry', -1, 'GEOMETRY', 2); .br .DE \fR GRASS can import this PostGIS polygon map as follows: \fC .DS .br v.in.ogr dsn="PG:host=localhost dbname=postgis user=neteler" layer=test \(rs .br output=test type=boundary,centroid .br v.db.select test .br v.info -t test .br .DE \fR .SS Geometry Converters .RS .IP PostGIS with shp2pgsql: .br shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql .br .IP e00pg: E00 to PostGIS filter, see also \fIv.in.e00\fR. .br .IP GDAL/OGR ogrinfo and ogr2ogr: GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS. .br ogr2ogr -f "PostgreSQL" shapefile ?? .br .RE .SH SEE ALSO \fI db.connect, db.execute, .br Database management in GRASS GIS, .br Help pages for database modules, .br SQL support in GRASS GIS \fR .br \fI PostgreSQL web site, .br pgAdmin graphical user interface .PP Book: PostgreSQL: Introduction and Concepts by Bruce Momjian .br PostgreSQL Documentation .br PostgreSQL Technical Documentation .br GDAL/OGR PostgreSQL driver documentation .br MapServer Wiki \fR .PP \fILast changed: $Date: 2011-02-07 18:59:50 +0100 (Mon, 07 Feb 2011) $\fR .br Help Index