databaseintro(1grass)

🌈 databaseintro(1grass) β€” Database management in GRASS πŸ’–

okay bestie, sit down, grab a strawberry πŸ“ because this is your whole crash course on how GRASS handles databases. it's giving "group project but make it SQL". let's gooo ✨


πŸ—‚οΈ Attribute management in general

GRASS can be linked to one or many database management systems (DBMS) β€” like, it's not monogamous, it plays the field. πŸ’…

  • the db.* set of commands gives you basic SQL support for attribute management
  • the v.db.* set of commands operates on the vector map (peep the Vector introduction for that lore πŸ¦‹)

πŸš— Available drivers

Available drivers are listed in SQL support in GRASS.

Notes, bestie, listen up πŸŽ€

The DBF driver provides only very limited SQL support (as DBF is not an SQL DB) β€” it's giving "trying its best" 😭. While the other DBMS backends (such as SQLite, PostgreSQL, MySQL etc) provide full SQL support, since the SQL commands are sent directly to the DBMS. For this reason, the SQLite driver is the default DBMI backend. πŸ‘‘


πŸ”Œ DB connection management

The current database management settings are shown or modified with db.connect for the current mapset.

Available DBMI drivers are listed with db.drivers.

Some DBMI backends require a user/password for driver/database to be set with db.login.

In order to test a driver, run db.test. πŸ§ͺ✨


πŸ“₯πŸ“€ Attribute data import and export

  • Attribute data can be imported with db.in.ogr from various formats 🫢
  • ...and exported with db.out.ogr πŸŽ€
  • To internally copy a full table or selectively parts of it, use db.copy.

Further conversion tools:

  • MDB Tools: Convert MS-Access data to SQL, DBF, etc. πŸ’€βž‘οΈβœ¨
  • Using OpenOffice.org with SQL Databases

πŸ’» SQL commands

GRASS supports two main SQL operations:

  1. execution of an SQL statement β€” that's db.execute πŸ”₯
  2. selection of data from a table β€” that's db.select πŸ‘‘

See the SQL help page for examples. iykyk πŸ’…


βš™οΈ Managing the default DBMI settings

Per default, vector map attributes are stored in SQLite tables. 🐚

This default definition can be modified with db.connect.

If an external DBMS is used, db.login may be required. πŸ”


πŸ—οΈ Creating a database

Specific commands are explained on the individual driver pages (heads up: these pages are only available if the driver was compiled in this installation πŸ™ˆ):

  • DBF: see DBF page
  • SQLite: SQLite page
  • mySQL: mySQL and meSQL pages
  • ODBC: ODBC page (connect to Oracle, etc.)
  • PostgreSQL: PostgreSQL and PostGIS page

πŸ” Metadata

  • All columns for a given table are listed with db.columns.
  • The command db.describe describes a table in detail.
  • To list all available tables for a given database, run db.tables.

literally your table's whole vibe check πŸͺž


🧹 Table maintenance

  • To drop a column from a selected attribute table, use db.dropcolumn.
  • With db.droptable an attribute table can be deleted.

bye bye column, bye bye table 😭✌️


🧬 Database Schema

Currently schema support only works for PostgreSQL connections. no cap.

Default schema can be set with db.connect. Note that the default schema will be used by all db.* modules. 🌸

db.tables returns 'schema.table' if schemas are available in the database.


🚚 Migrating to a different database engine

To migrate a GRASS database table (or a GRASS vector map) to a different DBMI engine, the best solution is:

  1. create a new MAPSET πŸŽ€
  2. define the DBMI settings accordingly with db.connect and if needed, db.login
  3. then the table of interest can be copied over with db.copy from the original MAPSET

Likewise, a vector map including its table(s) are copied from the original MAPSET to the current MAPSET with g.copy. πŸ¦‹


πŸ‘€ See also

  • Introduction into raster data processing
  • Introduction into 3D raster data (voxel) processing
  • Introduction into vector data processing
  • Introduction into image processing
  • Introduction into temporal data processing
  • Projections and spatial transformations

πŸ“œ SOURCE CODE

Available at: Database management in GRASS source code (history)

Accessed: Friday May 08 10:38:23 2026

Main index | Database index | Topics index | Keywords index | Graphical index | Full index

Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual


and that's the whole page, bestie 🫢 this is GRASS 8.5.0, databaseintro(1grass), periodt. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from