GRASS logo

SQL support in GRASS GIS

GRASS can use various RDBMS and embeded databases. SQL queries are directly passed to the underlying database system. The set of supported SQL commnads depends on the RDMBS and driver selected.

Drivers

The list of available drivers can vary in various binary distributions of GRASS.

dbfDBF files. Data are stored in DBF files. 
sqliteSQLite embeded database.http://sqlite.org/
pgPostgreSQL RDBMS.http://postgresql.org/
mysqlMySQL RDBMS.http://mysql.org/
mesqlMySQL embeded database.http://mysql.org/
odbcUnixODBC.http://www.unixodbc.org/

NOTES

EXAMPLES

Display all vector points except for LAMAR valley and extensive trapping (brackets are superfluous in this example):
d.vect trapping_sites_points fcol=black icon=basic/diamond col=white size=13 \
    where="valley <> 'LAMAR' OR (valley = 'LAMAR' AND description = 'extensive trapping')"

Select all attributes from table where str1 column values are not 'No Name':

echo "SELECT * FROM archsites WHERE str1 <> 'No Name'" | db.select

Example of null handling:

v.db.addcol map=roads col="nulltest int"
v.db.update map=roads col=nulltest value=1 where="cat > 2"
d.vect roads where="nulltest is null"
v.db.update map=roads col=nulltest value=2 where="cat <= 2"

Examples of complex expressions in updates (using v.db.* modules):

v.db.addcol map=roads col="exprtest double"
v.db.update map=roads col=exprtest value=cat/nulltest
v.db.update map=roads col=exprtest value=cat/nulltest+cat where=cat=1

Examples of complex expressions in updates (using db.* modules):

echo "UPDATE roads SET exprtest=null"
echo "UPDATE roads SET exprtest=cat/2" | db.execute
echo "UPDATE roads SET exprtest=cat/2+cat/3" | db.execute
echo "UPDATE roads SET exprtest=NULL WHERE cat>2" | db.execute
echo "UPDATE roads SET exprtest=cat/3*(cat+1) WHERE exprtest IS NULL" | db.execute"

You actually don't always have to create/update columns with expressions, but you can use them directly in other commands:

d.vect roads where="(cat/3*(cat+1))>8"
d.vect roads where="cat>exprtest"

Last changed: $Date: 2006/02/01 11:45:32 $



Help Index