1grass-pg(1)                   Grass User's Manual                  grass-pg(1)
2
3
4
5PostgreSQL driver in GRASS The driver name is 'pg'.
6

Creating a PostgreSQL database

8       A  new  database  is created with 'createdb', see the PostgreSQL manual
9       for details.
10

Connecting GRASS to PostgreSQL

12
13       # example for connecting to a PostgreSQL server:
14       db.connect driver=pg database="host=myserver.itc.it,dbname=mydb"
15       db.login user=myname pass=secret
16       db.connect -p
17       db.tables -p
18
19

Supported SQL commands

21       All SQL commands supported by PostgreSQL.
22

Operators available in conditions

24       All SQL operators supported by PostgreSQL.
25

Adding an unique ID column

27       Import vector module require an unique ID column which can be generated
28       as follows in a PostgreSQL table:
29       echo "
30        ALTER TABLE mytable ADD ID integer;
31        CREATE SEQUENCE mytable_seq;
32        UPDATE mytabe SET ID = nextval('mytable_seq');
33        DROP SEQUENCE mytable_seq;
34       " | db.execute
35
36

Attribute Converters

38       CSV import into PostgreSQL:
39       \h copy
40       COPY t1 FROM 'filename' USING DELIMITERS ',';
41        pg2xbase: DBF to PostgreSQL converter.
42

PostGIS: PostgreSQL with vector geometry

44       PostGIS: adds geographic object support to PostgreSQL.
45
46   Example: Import from PostGIS
47       In an existing PostGIS database, create the following table:
48       CREATE TABLE test
49       (
50        id serial NOT NULL,
51        mytime timestamp DEFAULT now(),
52        text varchar,
53        wkb_geometry geometry,
54        CONSTRAINT test_pkey PRIMARY KEY (id)
55       ) WITHOUT OIDS;
56       # insert value
57       INSERT INTO test (text, wkb_geometry)
58        VALUES ('Name',geometryFromText('POLYGON((600000 200000,650000
59        200000,650000 250000,600000 250000,600000 200000))',-1));
60       # register the table with geometry
61       select  AddGeometryColumn  ('postgis',  'test', 'geometry', -1, 'GEOMEā€
62       TRY', 2);
63        GRASS can import this PostGIS polygon map as follows:
64       v.in.ogr dsn="PG:host=localhost dbname=postgis user=neteler" layer=test
65       \
66                output=test type=boundary,centroid
67       v.db.select test
68       v.info -t test
69
70
71   Geometry Converters
72                     PostGIS with shp2pgsql:
73                     shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql
74
75                     e00pg: E00 to PostGIS filter, see also v.in.e00.
76
77                     GDAL/OGR ogrinfo and ogr2ogr: GIS vector format converter
78                     and library, e.g. ArcInfo or SHAPE to PostGIS.
79                     ogr2ogr -f "PostgreSQL" shapefile ??
80

SEE ALSO

82        db.connect, db.execute,
83       Database management in GRASS GIS,
84       Help pages for database modules,
85       SQL support in GRASS GIS
86        PostgreSQL web site,
87       pgAdmin graphical user interface
88
89       Book: PostgreSQL: Introduction and Concepts by Bruce Momjian
90       PostgreSQL Documentation
91       PostgreSQL Technical Documentation
92       GDAL/OGR PostgreSQL driver documentation
93       MapServer Wiki
94
95       Last changed: $Date: 2007-11-24 13:41:10 +0100 (Sat, 24 Nov 2007) $
96       Help Index
97
98
99
100GRASS 6.3.0                                                        grass-pg(1)
Impressum