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 of libsqlitefunctions.so and libsqlitefunctions.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