v.db.update(1grass)
π v.db.update β the GRASS User's Manual glow-up β¨
okay bestie, sit down, hydrate, because today we're talking about v.db.update from the GRASS User's Manual and she is that girl. π«Ά
β¨ NAME β¨
v.db.update β literally updates a column in the attribute table connected to a vector map. that's the whole job. she does it flawlessly. π
π KEYWORDS π
<vector, attribute table, database, attribute update, type casting> β yes, all of those, she contains multitudes. π
πΈ SYNOPSIS πΈ
v.db.update
v.db.update --help
v.db.update map=name layer=string column=name [value=string]
[query_column=name] [where=sql_query] [sqliteextra=name] [--help]
[--verbose] [--quiet] [--ui]
π¦ Flags
--helpβ prints the usage summary so you're not out here guessing. π--verboseβ verbose module output, aka she tells you everything. main character narration. π--quietβ quiet module output, aka she says nothing. mysterious. iconic. π€«--uiβ force launches the GUI dialog, for when you want the pretty buttons. β¨
π Parameters
map=name[required] β name of the vector map. or, plot twist, the data source for direct OGR access. two jobs, no complaints. πlayer=string[required] β layer number or name. vector features can have category values in different layers, and this number decides which layer we're on. when you're doing direct OGR access, this is the layer name instead. Default:1. periodt. πcolumn=name[required] β name of the attribute column to update. the target. the chosen one. π―value=stringβ a literal value to update that column with. just, like, hand her the thing. πquery_column=nameβ name of another attribute column to query, and yes she can be a combination of columns (e.g.co1+col2). math girlie. π₯where=sql_queryβ WHERE conditions of an SQL statement, noβwhereβkeyword needed (don't add it, bestie, she knows). example:income < 1000 and population >= 10000. π§sqliteextra=nameβ name of a SQLite extension file for extra functions. SQLite backend only, so don't come at her with anything else. π
π DESCRIPTION π
v.db.update assigns a new value to a column in the attribute table connected to a given map. the value parameter is how you update with a literal value. and 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. it's giving "one tool, so many dreams". π¦β¨
π₯ NOTES π₯
ngl, v.db.update is just a front-end to db.execute, but make it easier to use. that's the whole plot. π
for complex SQL UPDATE statements though? use db.execute. no cap, she said it herself. π«Ά
π EXAMPLES π
π Replacing of NULL values
so in this example, we selectively display lakes without (blue) and with NULL (red) so we can clock which type is undefined. in the original map there are lakes missing the FTYPE attribute, and those are wetlands along streams. these NULL attributes get 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 vector=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
π Updating of columns with on the fly calculation
Spearfish example, bestie: adding a new column, then copying values from another table column with an on-the-fly calculation. yes, on the fly. she's fast like that. π«
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 casting
type cast (type conversion) of strings to double precision β and heads up, this one is unsupported by the 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β"
π Updating of columns with on the fly calculation (SQLite extended functions)
Note: this requires SQLite extended functions. for details see the GRASS Wiki (compilation oflibsqlitefunctions.soandlibsqlitefunctions.dll). don't skip this part, queen. π
North Carolina data set example: adding a new column and copying values from another table column with an on the fly calculation:
g.copy vect=precip_30ynormals,myprecip_30ynormals
v.db.addcolumn myprecip_30ynormals column="logjuly double precision"
v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \
sqliteextra=$HOME/sqlite_extensions/libsqlitefunctions.so
v.db.select myprecip_30ynormals columns=jul,logjuly
jul|logjuly
132.842|4.88916045210132
127|4.84418708645859
124.206|4.82194147751127
104.648|4.65060233738593
98.298|4.58800368106618
...
π«Ά 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) β we love an author with a whole email address. respect. π
β SOURCE CODE β
Available at: v.db.update source code (history)
Latest change: Friday Aug 08 09:39:19 2025 in commit: ed72c71d8580e872cd6fd345c84a15c324764465
Main index | Vector 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, brought to you by v.db.update(1grass), go forth and update those columns responsibly. πΈβ¨π
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms