grass-pg(1grass)
πβ¨ PostgreSQL DATABASE DRIVER β¨π
okay bestie, welcome to grass-pg(1grass) β straight out of the GRASS User's Manual π this is the page that tells you how to hook GRASS up to Postgres, and honestly? it's giving iconic.
So what even is this. The PostgreSQL database driver enables GRASS to store vector attributes in a PostgreSQL server. that's the whole vibe. attributes? in postgres? yes. slay. π
πΈ Creating a PostgreSQL database πΈ
A new database is created with createdb. that's it, that's the tea. go read the PostgreSQL manual for the deets, i'm not gonna hold your hand through that one π«Ά
π Connecting GRASS to PostgreSQL π
Here's your lil starter pack, copy it and go:
# example for connecting to a PostgreSQL server:
db.connect driver=pg database=mydb
db.login user=myname password=secret host=myserver.osgeo.org # port=5432
db.connect -p
db.tables -p
look at that. beautiful. no notes. π
π Username and password π
straight from the PostgreSQL manual, quote unquote:
The file .pgpass in a user's home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Microsoft Windows the file is named %APPDATA%\postgresql\pgpass.conf (where %APPDATA% refers to the Application Data subdirectory in the user's profile). Alternatively, a password file can be specified using the connection parameter passfile or the environment variable PGPASSFILE. This file should contain lines of the following format:
hostname:port:database:username:password
that's the format fr fr. memorize it or don't, it's your life π
π Supported SQL commands π
All SQL commands supported by PostgreSQL. iconic, generous, we love her.
β οΈ but NOT possible to use C-like escapes (with backslash like \n etc) within the SQL syntax. so don't try it. she said no. π«
β Operators available in conditions β
All SQL operators supported by PostgreSQL. that's right, all of them. go feral. π₯
π Adding an unique ID column π
okay this one matters β the Import vector module require an unique ID column, and you can generate one like this in a PostgreSQL table:
db.execute sql="ALTER TABLE mytable ADD ID integer"
db.execute sql="CREATE SEQUENCE mytable_seq"
db.execute sql="UPDATE mytable SET ID = nextval(βmytable_seqβ)"
db.execute sql="DROP SEQUENCE mytable_seq"
four commands, one unique ID, zero drama β¨
π₯ Attribute import into PostgreSQL π₯
CSV import into PostgreSQL, as follows:
\h copy
COPY t1 FROM βfilenameβ USING DELIMITERS β,β;
easy peasy bestie π
πΊοΈ Geometry import from PostgreSQL table into GRASS πΊοΈ
v.in.db creates a new vector (points) map from a database table containing coordinates. See here for examples. yes, points. spatial. main character energy, honestly π
π PostGIS: PostgreSQL with vector geometry π
PostGIS: adds geographic object support to PostgreSQL. so postgres but with geography. the glow up was real π¦
π Example: Import from PostGIS π
In an existing PostGIS database, create the following table:
CREATE TABLE test
(
id serial NOT NULL,
mytime timestamp DEFAULT now(),
text varchar,
wkb_geometry geometry,
CONSTRAINT test_pkey PRIMARY KEY (id)
) WITHOUT OIDS;
# insert value
INSERT INTO test (text, wkb_geometry)
VALUES (βNameβ,geometryFromText(βPOLYGON((600000 200000,650000
200000,650000 250000,600000 250000,600000 200000))β,-1));
# register geometry column
select AddGeometryColumn (βpostgisβ, βtestβ, βgeometryβ, -1, βGEOMETRYβ, 2);
GRASS can import this PostGIS polygon map as follows:
v.in.ogr input="PG:host=localhost dbname=postgis user=neteler" layer=test \
output=test type=boundary,centroid
v.db.select test
v.info -t test
look at her go. polygon in, polygon out. periodt π
π Geometry Converters π
- PostGIS with
shp2pgsql:
shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql
e00pg: E00 to PostGIS filter, see alsov.in.e00.- GDAL/OGR
ogrinfoandogr2ogr: GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS.
ogr2ogr -f "PostgreSQL" shapefile ??
(yes that ?? is in there, no i do not know, don't ask me, i'm just the messenger π)
π SEE ALSO π
db.connect,db.execute- Database management in GRASS
- Help pages for database modules
- SQL support in GRASS
π REFERENCES π
- PostgreSQL web site
- pgAdmin graphical user interface
- GDAL/OGR PostgreSQL driver documentation
πΎ SOURCE CODE πΎ
Available at: PostgreSQL DATABASE DRIVER source code (history)
Accessed: Tuesday Sep 08 11:54:02 2026
Main index | Topics index | Keywords index | Graphical index | Full index
and that's the whole page bestie π«Ά tysm for reading, you absolutely ate that. this came to you courtesy of the π GRASS Development Team π, Β© 2003-2026, from the GRASS 8.5.0 Reference Manual, and yes this whole masterpiece lives under the name grass-pg(1grass) in GRASS 8.5.0. mwah πβ¨π
π¦ where this page comes from
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms