db.execute(1)
β¨ db.execute β¨
okay so bestie, welcome to db.execute(1) from the GRASS GIS User's Manual π this is the girl who runs your SQL for you and doesn't even ask for a thank you.
KEYWORDS: database, attribute table, SQL π
πΈ NAME πΈ
db.execute β she executes any SQL statement. literally any. periodt.
heads up babes: forSELECTstatements you wantdb.selectinstead, not her π
π¦ 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 keep going like nothing happened π--helpβ prints the usage summary, the lil recap--verboseβ verbose module output, she's chatty now--quietβ quiet module output, she's giving mysterious--uiβ force launching the GUI dialog, main character GUI energy π
β¨ Parameters β¨
sql=sql_queryβ the SQL statement itself- Example:
update rybniky set kapri = 'hodne' where kapri = 'malo'
- Example:
input=nameβ name of the file containing your SQL statement(s)- use
'-'for standard input π«Ά
- use
driver=nameβ name of the database driver- Options:
dbf,mesql,mysql,odbc,ogr,pg,sqlite - Default:
sqlite
- Options:
database=nameβ name of the database- Default:
$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
- Default:
schema=nameβ database schema- > do not use this option if schemas aren't supported by your driver / database server, no cap
π DESCRIPTION π
db.execute allows the user to execute SQL statements. that's it, that's the whole vibe. iconic behaviour, honestly.
π NOTES π
db.execute only executes SQL statements and does not return any data. if you need data coming back to you, that's a db.select moment bestie, don't get it twisted π
if your parameters for the database connection are already set with db.connect, they get taken as default values and you don't have to re-specify them every single time. she remembers. she's thoughtful like that. π
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. fr fr, the loop is not the move here. and if multiple instruction lines are given, each SQL line must end with a semicolon. every single one. no skipping. π
please see the individual GRASS SQL interface for how to create a new database. iykyk.
π₯ 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)
Accessed: Saturday Jan 17 05:40:34 2026
Main index | Database 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!! this was GRASS 8.4.2, page db.execute(1), source + version + date all up there for you, mwah πβ¨π go run some SQL and slay π¦
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· 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