Provided by: grass-doc_7.6.1-3build1_all bug


       db.execute  - Executes any SQL statement.
       For SELECT statements use ’’.


       database, attribute table, SQL


       db.execute --help
       db.execute   [-i]    [sql=sql_query]     [input=name]     [driver=name]    [database=name]
       [schema=name]   [--help]  [--verbose]  [--quiet]  [--ui]

           Ignore SQL errors and continue

           Print usage summary

           Verbose module output

           Quiet module output

           Force launching GUI dialog

           SQL statement
           Example: update rybniky set kapri = ’hodne’ where kapri = ’malo’

           Name of file containing SQL statement(s)
           ’-’ for standard input

           Name of database driver
           Options: dbf, mysql, odbc, ogr, pg, sqlite
           Default: sqlite

           Name of database
           Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db

           Database schema
           Do not use this option if schemas are not supported by driver/database server


       db.execute allows the user to execute SQL statements.


       db.execute only executes SQL statements and does not return any data.  If  you  need  data
       returned from the database, use

       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.

       If you have a large number of SQL commands to process, it is much much faster to place all
       the  SQL  statements  into  a text file and use input file parameter than it is to process
       each statement individually in a loop. 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.


       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
       # ’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"


        db.columns, db.describe, db.drivers, db.droptable, db.login,, db.tables,

        GRASS SQL interface



       Last changed: $Date: 2014-11-28 10:57:47 +0100 (Fri, 28 Nov 2014) $


       Available at: db.execute source code (history)

       Main index | Database index | Topics index | Keywords index | Graphical index | Full index

       © 2003-2019 GRASS Development Team, GRASS GIS 7.6.1 Reference Manual