.TH grass-pg 1grass "" "GRASS 6.4.4" "Grass User's Manual" .SH NAME grass-pg \- PostgreSQL driver PostgreSQL driver PostgreSQL DB driver in GRASS .SH KEYWORDS database, attribute table, driver .SH DESCRIPTION The DB (database) driver name in GRASS is \fBpg\fR. .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 the 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 db.execute sql="ALTER TABLE mytable ADD ID integer" .br db.execute sql="CREATE SEQUENCE mytable_seq" .br db.execute sql="UPDATE mytable SET ID = nextval('mytable_seq')" .br db.execute sql="DROP SEQUENCE mytable_seq" .br .DE \fR .SH Attribute import into PostgreSQL CSV import into PostgreSQL: \fC .DS .br \(rsh copy .br COPY t1 FROM 'filename' USING DELIMITERS ','; .br .DE \fR .SH Geometry import from PostgreSQL table into GRASS \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 .IP e00pg: E00 to PostGIS filter, see also \fIv.in.e00\fR. .IP GDAL/OGR ogrinfo and ogr2ogr: GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS. .br ogr2ogr \-f "PostgreSQL" shapefile ?? .RE .SH SEE ALSO \fI db.connect, db.execute \fR .PP Database management in GRASS GIS, .br Help pages for database modules, .br SQL support in GRASS GIS .br .SH REFERENCES .RS .IP PostgreSQL web site .IP pgAdmin graphical user interface .IP GDAL/OGR PostgreSQL driver documentation .RE .PP \fILast changed: $Date: 2014-02-03 17:26:56 +0100 (Mon, 03 Feb 2014) $\fR .br Main index - Database index - Full index .PP © 2003-2014 GRASS Development Team, GRASS GIS 6 Reference Manual