1db.execute(1)               GRASS GIS User's Manual              db.execute(1)
2
3
4

NAME

6       db.execute  - Executes any SQL statement.
7       For SELECT statements use ’db.select’.
8

KEYWORDS

10       database, attribute table, SQL
11

SYNOPSIS

13       db.execute
14       db.execute --help
15       db.execute   [-i]    [sql=sql_query]     [input=name]     [driver=name]
16       [database=name]    [schema=name]    [--help]   [--verbose]    [--quiet]
17       [--ui]
18
19   Flags:
20       -i
21           Ignore SQL errors and continue
22
23       --help
24           Print usage summary
25
26       --verbose
27           Verbose module output
28
29       --quiet
30           Quiet module output
31
32       --ui
33           Force launching GUI dialog
34
35   Parameters:
36       sql=sql_query
37           SQL statement
38           Example: update rybniky set kapri = ’hodne’ where kapri = ’malo’
39
40       input=name
41           Name of file containing SQL statement(s)
42           ’-’ for standard input
43
44       driver=name
45           Name of database driver
46           Options: dbf, mesql, mysql, odbc, ogr, pg, sqlite
47           Default: sqlite
48
49       database=name
50           Name of database
51           Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
52
53       schema=name
54           Database schema
55           Do not use this option if schemas are not supported by driver/data‐
56           base server
57

DESCRIPTION

59       db.execute allows the user to execute SQL statements.
60

NOTES

62       db.execute only executes SQL statements and does not return  any  data.
63       If you need data returned from the database, use db.select.
64
65       If  parameters for database connection are already set with db.connect,
66       they are taken as default values and do not need to be  specified  each
67       time.
68
69       If  you have a large number of SQL commands to process, it is much much
70       faster to place all the SQL statements into a text file and  use  input
71       file  parameter  than it is to process each statement individually in a
72       loop. If multiple instruction lines are given, each SQL line  must  end
73       with a semicolon.
74
75       Please  see  the individual GRASS SQL interface for how to create a new
76       database.
77

EXAMPLES

79       Create a new table with columns ’cat’ and ’soiltype’:
80       db.execute sql="CREATE TABLE soils (cat integer, soiltype varchar(10))"
81       Create a new table using a file with SQL statements
82       db.execute driver=odbc database=grassdb input=file.sql
83       Insert new row into attribute table:
84       db.execute sql="INSERT INTO mysites (id,name,east,north) values (30,’Ala’,1657340,5072301)"
85       Update attribute entries to new value based on SQL rule:
86       db.execute sql="UPDATE roads SET travelcost=5 WHERE cat=1"
87       Update attribute entries to new value based on SQL rule:
88       db.execute sql="UPDATE dourokukan SET testc=50 WHERE testc is NULL"
89       Delete selected rows from attribute table:
90       db.execute sql="DELETE FROM gsod_stationlist WHERE latitude < -91"
91       Add new column to attribute table:
92       db.execute sql="ALTER TABLE roads ADD COLUMN length double"
93       Column type conversion - update new column from  existing  column  (all
94       drivers except for DBF):
95       # ’z_value’ is varchar and ’z’ is double precision:
96       echo "UPDATE geodetic_pts SET z = CAST(z_value AS numeric)" | db.execute input=-
97       Drop column from attribute table:
98       db.execute sql="ALTER TABLE roads DROP COLUMN length"
99       Drop table (not supported by all drivers):
100       db.execute sql="DROP TABLE fmacopy"
101       Update   attribute  with  multiple  SQL  instructions  in  file  (e.g.,
102       file.sql, instruction line must end with a semicolon):
103       UPDATE roads SET travelcost=5 WHERE cat=1;
104       UPDATE roads SET travelcost=2 WHERE cat=2;
105       db.execute input=file.sql
106       Join table ’myroads’ to table ’extratab’ based on common  ’cat’  column
107       values (not supported by DBF driver):
108       db.execute sql="UPDATE extratab SET names=(SELECT label FROM myroads WHERE extratab.cat=myroads.cat)"
109

SEE ALSO

111          db.columns,   db.describe,   db.drivers,   db.droptable,   db.login,
112       db.select, db.tables,
113
114        GRASS SQL interface
115

AUTHOR

117       CERL
118

SOURCE CODE

120       Available at: db.execute source code (history)
121
122       Main index | Database index | Topics index | Keywords index | Graphical
123       index | Full index
124
125       © 2003-2020 GRASS Development Team, GRASS GIS 7.8.5 Reference Manual
126
127
128
129GRASS 7.8.5                                                      db.execute(1)
Impressum