grass-odbc(1)

πŸ’– ODBC DATABASE DRIVER πŸ’–

hii bestie, welcome to grass-odbc(1) β€” the plug that lets GRASS and an ODBC database talk about attributes like the besties they are 🫢 it's all about communication between GRASS and ODBC database for attribute management, and the whole pipeline goes a lil something like this:

GRASS module <-> ODBC Interface <-> RDBMS

GRASS
  DBMI driver
  unixODBC
  ODBC driver
  PostgreSQL
  Oracle
  ...

so yeah, GRASS on one end, your RDBMS on the other (PostgreSQL, Oracle, and friends), with the ODBC Interface living its best life in the middle ✨


✨ Supported SQL commands

literally all of them. every SQL command that ODBC supports is supported here. periodt πŸ’…

✨ Operators available in conditions

same energy β€” all SQL operators supported by ODBC. all of them. no notes πŸ‘‘


🌸 EXAMPLE 🌸

ok so in this example we're gonna copy the dbf file of a SHAPE map into ODBC, and then connect GRASS to the ODBC DBMS πŸ¦‹ usually the table will already be sitting there in the DBMS, but we're doing the whole thing from scratch for the vibes.

πŸŽ€ Defining the ODBC connection πŸŽ€

πŸ–₯️ MS-Windows

on MS-Windows, to be able to connect, the ODBC connection needs to be configured using dedicated tools (the tool is literally called "ODBC Data Source Administrator") and you gotta give a name to that connection. that name is then used as the database name when accessing from a client via ODBC. iykyk πŸ’…

🐧 Linux

configure the ODBC driver for the selected database (manually, or with ’ODBCConfig’). ODBC drivers are defined in /etc/odbcinst.ini. here's an example:

[PostgreSQL]
Description     = ODBC for PostgreSQL
Driver          = /usr/lib/libodbcpsql.so
Setup           = /usr/lib/libodbcpsqlS.so
FileUsage       = 1

then create the DSN (data source name). the DSN is used as the database name in db.* modules. the DSN must be defined in $HOME/.odbc.ini (for this user only) or in /etc/odbc.ini (for all users).

⚠️ watch out for the database name which appears twice, and also for the PostgreSQL protocol version. and omit blanks at the beginning of lines β€” no leading spaces bestie, i'm serious 😭
[grass6test]
Description             = PostgreSQL
Driver                  = PostgreSQL
Trace                   = No
TraceFile               =
Database                = grass6test
Servername              = localhost
UserName                = neteler
Password                =
Port                    = 5432
Protocol                = 8.0
ReadOnly                = No
RowVersioning           = No
ShowSystemTables        = No
ShowOidColumn           = No
FakeOidIndex            = No
ConnSettings            =

configuration of a DSN without a GUI is described on https://www.unixodbc.org/odbcinst.html, but odbc.ini and .odbc.ini may be created by the ’ODBCConfig’ tool. you can easily view your DSN structure with ’DataManager’. configuration with GUI is described on https://www.unixodbc.org/doc/UserManual/ 🌈

to find out about your PostgreSQL protocol, run:

psql -V

πŸ¦‹ Using the ODBC driver

now create a new database if it's not already existing:

db.createdb driver=odbc database=grass6test

to store a table ’mytable.dbf’ (here: in the current directory) into PostgreSQL through ODBC, run:

db.connect driver=odbc database=grass6test
db.copy from_driver=dbf from_database=./ from_table=mytable \
        to_driver=odbc to_database=grass6test to_table=mytable

next, link the map to the attribute table (now the ODBC table is used, not the dbf file):

v.db.connect map=mytable.shp table=mytable key=ID \
             database=grass6test driver=odbc
v.db.connect -p

finally, a test: here we should see the table columns (if the ODBC connection works):

db.tables -p
db.columns table=mytable

now the table name ’mytable’ should appear πŸ‘‘

doesn't work? check with ’isql <databasename>’ if the ODBC-PostgreSQL connection is really established πŸ”

note that you can also connect mySQL, Oracle etc. through ODBC to GRASS πŸ’…

you can also check the vector map itself concerning a current link to a table:

v.db.connect -p mytable.shp

which should print the database connection through ODBC to the defined RDBMS. slay.


πŸ‘€ SEE ALSO

  • db.connect
  • v.db.connect
  • unixODBC web site
  • SQL support in GRASS GIS

πŸ“œ SOURCE CODE

available at: ODBC DATABASE DRIVER source code (history)

accessed: Saturday Jan 17 05:40:32 2026

main index | topics index | keywords index | graphical index | full index


and that's the whole page bestie 🫢 this was grass-odbc(1) from the GRASS GIS 8.4.2 Reference Manual β€” Β© 2003-2025 GRASS Development Team, and the footer energy is pure GRASS 8.4.2 / grass-odbc(1). go connect something iconic πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from