GRASS logo

Note: A new GRASS GIS stable version has been released: GRASS GIS 7. Go directly to the new manual page here


v.db.update - Updates a column in the attribute table connected to a vector map.


vector, database, attribute table


v.db.update help
v.db.update map=string [layer=string] column=string [value=string] [qcolumn=string] [where=string] [--verbose] [--quiet]


Vector map to edit the attribute table for
Layer to which the table to be changed is connected
Default: 1
Column to update
Literal value to update the column with
Varchar values must be in single quotes, e.g. 'grass'
Name of attribute column to query
Can be a combination of columns, e.g. col1+col2
WHERE conditions for update, without 'where' keyword (e.g. cat=1 or col1/col2>1)


v.db.update assigns a new value to a column in the attribute table connected to a given map. The value parameter updates with a literal value. Alternatively, with the qcol parameter values can be copied from another column in the table or be the result of a combination or transformation of other columns.


v.db.update is just a front-end to db.execute to allow easier usage.

For complex SQL UPDATE statements, db.execute should be used.


In this example, selectively display lakes without (blue) and with NULL (red) are shown to find out which type is undefined. In the original map there are lakes missing FTYPE attribute which are wetlands along streams. These NULL attributes are replaced with the landuse type WETLAND:
g.copy vect=lakes,mylakes mylakes mylakes where="FTYPE IS NULL"

# display the lakes, show undefined FTYPE lakes in red
g.region vect=mylakes
d.mon x0
d.vect mylakes where="FTYPE NOT NULL" type=area col=blue
d.vect mylakes where="FTYPE IS NULL" type=area col=red

# replace NULL with FTYPE WETLAND
v.db.update mylakes col=FTYPE value=WETLAND \
            where="FTYPE IS NULL" mylakes

Spearfish example: adding new column, copying values from other table column with on the fly calculation:

g.copy vect=fields,myfields
v.db.addcol myfields col="polynum integer"
v.db.update myfields col=polynum qcol="cat*2" myfields

Type cast (type conversion) of strings to double precision (unsupported by DBF driver):

g.copy vect=geodetic_pts,mygeodetic_pts
v.db.update mygeodetic_pts col=zval qcol="CAST(z_value AS double precision)" \
            where="z_value <> 'N/A'"


db.execute, v.db.addcol, v.db.addtable, v.db.connect, v.db.droptable, v.db.join,
GRASS SQL interface


Moritz Lennert (

Last changed: $Date: 2013-05-02 02:29:18 -0700 (Thu, 02 May 2013) $

Main index - vector index - Full index

© 2003-2016 GRASS Development Team