
NAME
v.db.update - Allows to update a column in the attribute table connected to a vector map.
KEYWORDS
vector, database, attribute table
SYNOPSIS
v.db.update
v.db.update help
v.db.update map=name layer=string column=name [value=string] [qcolumn=name] [where=sql_query] [--verbose] [--quiet]
Parameters:
- map=name [required]
- Name of vector map
- Or data source for direct OGR access
- layer=string [required]
- Layer number or name
- A single vector map can be connected to multiple database tables. This number determines which table to use. When used with direct OGR access this is the layer name.
- Default: 1
- column=name [required]
- Name of attribute column to update
- value=string
- Value to update the column with, can be (combination of) other column(s)
- qcolumn=name
- Name of attribute column to query
- where=sql_query
- WHERE conditions of SQL statement without 'where' keyword
- Example: income < 1000 and inhab >= 10000
DESCRIPTION
v.db.update allows to assign a new value to a column in the
attribute table connected to a given map. Alternatively, values can be
copied from another column in the table.
NOTES
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.
EXAMPLES
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
v.db.select mylakes
v.db.select mylakes where="FTYPE IS NULL"
# display the lakes, show undefined FTYPE lakes in red
g.region vect=mylakes
d.mon wx0
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"
v.db.select mylakes
Spearfish example: adding new column, copying values from other table
column with on the fly calculation:
g.copy vect=fields,myfields
v.db.addcolumn myfields col="polynum integer"
v.db.update myfields col=polynum qcol="cat*2"
v.db.select 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'"
SEE ALSO
db.execute,
v.db.addcolumn,
v.db.addtable,
v.db.connect,
v.db.droptable,
v.db.join,
v.db.select
GRASS SQL interface
AUTHOR
Moritz Lennert (mlennert@club.worldonline.be)
Last changed: $Date: 2011-11-08 13:24:20 -0800 (Tue, 08 Nov 2011) $
Main index - Vector index - Full index
© 2003-2012 GRASS Development Team