v.db.update(1)

πŸ’– v.db.update πŸ’–

okay so bestie, gather round, because this is v.db.update(1) from the GRASS GIS User's Manual (you're on GRASS 8.4.2, no cap) and it is literally the glow-up tool for your attribute tables. it updates a column in the attribute table connected to a vector map. that's the whole vibe. ✨


🌸 NAME 🌸

v.db.update β€” updates a column in the attribute table connected to a vector map.


πŸŽ€ KEYWORDS πŸŽ€

vector, attribute table, database, attribute update, type casting


✨ 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, i.e. the "what is this" card for when you forgot.
  • --verbose β€” verbose module output. she's chatty.
  • --quiet β€” quiet module output. she's mysterious.
  • --ui β€” force launches the GUI dialog. main character energy, but make it clickable.

πŸ“ Parameters

  • map=name [required] β€” the name of the vector map. or, plot twist, a data source for direct OGR access.
  • layer=string [required] β€” layer number or name. vector features can have category values in different layers, and this number determines which layer to use. when you're doing direct OGR access, this is the layer name instead. Default: 1
  • column=name [required] β€” the name of the attribute column you're updating. yes, this one. this is the one.
  • value=string β€” a literal value to update the column with. just plop it right in there.
  • query_column=name β€” the name of another attribute column to query. it can be a combination of columns too, like co1+col2. (you'll see it written as qcol= in the examples below, iykyk.)
  • where=sql_query β€” WHERE conditions of the SQL statement, without the where keyword. Example: income < 1000 and population >= 10000
  • sqliteextra=name β€” name of the SQLite extension file for extra functions (SQLite backend only).

πŸ’… DESCRIPTION πŸ’…

v.db.update assigns a new value to a column in the attribute table connected to a given map. the value parameter lets you update with a literal value. alternatively, with the query_column parameter, values can be copied from another column in the table, or they can be the result of a combination or transformation of other columns. it's giving flexible. it's giving powerful. it's giving database wizardry.


πŸ”₯ NOTES πŸ”₯

v.db.update is just a front-end to db.execute, so it can be easier to use. that's it, that's the tea. πŸ«–

for complex SQL UPDATE statements, db.execute should be used. like, actually use it. don't come for me later.

🌈 EXAMPLES 🌈

πŸ’™ Replacing of NULL values

in this example, selectively displaying lakes without (blue) and with NULL (red) are shown so you can find out which type is undefined. in the original map there are lakes missing the FTYPE attribute which are wetlands along streams. those 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 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: adding a new column, then copying values from another 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 casting

type cast (type conversion) of strings to double precision β€” heads up, this 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 GIS Wiki (compilation of libsqlitefunctions.so and libsqlitefunctions.dll).

North Carolina data set example: adding a new column, then copying values from another table column with 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)


πŸ’– SOURCE CODE πŸ’–

Available at: v.db.update source code (history)

Accessed: Saturday Jan 17 05:41:53 2026

Main index | Vector index | Topics index | Keywords index | Graphical index | Full index

Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual


and that's the whole page bestie πŸ’…βœ¨ shoutout to the GRASS Development Team for the Β© 2003-2025 and the GRASS GIS 8.4.2 Reference Manual, accessed Saturday Jan 17 05:41:53 2026 β€” you ate, fr fr. now go update that column. periodt. πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from