db.execute(1grass)
πΈ NAME πΈ
db.execute β she runs any SQL statement you throw at her. That's it, that's the whole vibe.
And heads up bestie: if you want a SELECT (like, you actually want data back), go use db.select instead. db.execute is not the one for that. π
π KEYWORDS π
database, attribute table, SQL
β¨ SYNOPSIS β¨
db.execute
db.execute --help
db.execute [-i] [sql=sql_query] [input=name] [driver=name]
[database=name] [schema=name] [--help] [--verbose] [--quiet]
[--ui]
π© Flags π©
-iβ ignore SQL errors and justβ¦ keep going. Living her life, unbothered. π--helpβ print usage summary--verboseβ verbose module output--quietβ quiet module output--uiβ force launching GUI dialog
π Parameters π
sql=sql_queryβ the SQL statement itself, queen. Example:update rybniky set kapri = βhodneβ where kapri = βmaloβinput=nameβ name of file containing SQL statement(s). Use-for standard input.driver=nameβ name of database driver. Options:dbf,mysql,odbc,ogr,pg,sqliteDefault:sqlitedatabase=nameβ name of database. Default:$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.dbschema=nameβ database schema. Do not use this option if schemas are not supported by driver/database server. (like, read that twice, fr fr)
π« DESCRIPTION π«
db.execute allows the user to execute SQL statements. Short, sweet, iconic. β¨
π NOTES π
Okay so, the tea: db.execute only executes SQL statements and does not return any data. If you need data returned from the database, use db.select. No cap.
If parameters for database connection are already set with db.connect, they are taken as default values and do not need to be specified each time. Which is giving convenience, honestly. π«Ά
If you have a large number of SQL commands to process, it is much faster to place all the SQL statements into a text file and use the input file parameter than it is to process each statement individually in a loop. Trust. And if multiple instruction lines are given, each SQL line must end with a semicolon.
Please see the individual GRASS SQL interface for how to create a new database. π
π₯ EXAMPLES π₯
Create a new table with columns cat and soiltype:
db.execute sql="CREATE TABLE soils (cat integer, soiltype varchar(10))"
Create a new table using a file with SQL statements:
db.execute driver=odbc database=grassdb input=file.sql
Insert new row into attribute table:
db.execute sql="INSERT INTO mysites (id,name,east,north) values (30,βAlaβ,1657340,5072301)"
Update attribute entries to new value based on SQL rule:
db.execute sql="UPDATE roads SET travelcost=5 WHERE cat=1"
Update attribute entries to new value based on SQL rule:
db.execute sql="UPDATE dourokukan SET testc=50 WHERE testc is NULL"
Delete selected rows from attribute table:
db.execute sql="DELETE FROM gsod_stationlist WHERE latitude < -91"
Add new column to attribute table:
db.execute sql="ALTER TABLE roads ADD COLUMN length double"
Column type conversion - update new column from existing column (all drivers except for DBF):
# βz_valueβ is varchar and βzβ is double precision:
echo "UPDATE geodetic_pts SET z = CAST(z_value AS numeric)" | db.execute input=-
Drop column from attribute table:
db.execute sql="ALTER TABLE roads DROP COLUMN length"
Drop table (not supported by all drivers):
db.execute sql="DROP TABLE fmacopy"
Update attribute with multiple SQL instructions in file (e.g., file.sql, instruction line must end with a semicolon):
UPDATE roads SET travelcost=5 WHERE cat=1;
UPDATE roads SET travelcost=2 WHERE cat=2;
db.execute input=file.sql
Join table myroads to table extratab based on common cat column values (not supported by DBF driver):
db.execute sql="UPDATE extratab SET names=(SELECT label FROM myroads WHERE extratab.cat=myroads.cat)"
π SEE ALSO π
db.columns, db.describe, db.drivers, db.droptable, db.login, db.select, db.tables,
GRASS SQL interface
π AUTHOR π
CERL
π¦ SOURCE CODE π¦
Available at: db.execute source code (history)
Latest change: Friday Feb 07 19:16:09 2025 in commit: a82a39f673b97fafcfce1604dc3e6015cb96487a
Main index | Database index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole page, you ate it, you read it, slay π β¨
Little sign-off for the bestie who made it to the bottom: this was GRASS 8.5.0, Β© 2003-2026 GRASS Development Team, straight outta the GRASS 8.5.0 Reference Manual. Mwah. ππ«ΆπΈ
π¦ 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