1sql(1) Grass User's Manual sql(1)
2
3
4
6 GRASS can use various RDBMS and embedded databases. SQL queries are
7 directly passed to the underlying database system. The set of sup‐
8 ported SQL commands depends on the RDMBS and driver selected.
9
11 The list of available drivers can vary in various binary distributions
12 of GRASS.
13
14 | dbfDBF files. Data are stored in DBF files. | http://shapelib.map‐
15 tools.org/dbf_api.html | sqliteSQLite embedded database. |
16 http://sqlite.org/ | pgPostgreSQL RDBMS. | http://postgresql.org/ |
17 mysqlMySQL RDBMS. | http://mysql.org/ | mesqlMySQL embedded database.
18 | http://mysql.org/ | odbcUnixODBC. (PostgreSQL, Oracle, etc.) |
19 http://www.unixodbc.org/
20
22 SQL does not support '.' (dots) in table names.
23
24 Supported table name characters are only:
25 [A-Za-z][A-Za-z0-9_]*
26
27 A table name must start with a character, not a number.
28
29 Text-string matching requires the text part to be 'sin‐
30 gle quoted'. When run from the command line multiple
31 queries should be contained in "double quotes". e.g.
32
33 d.vect map where="individual='juvenile' and area='beach'"
34
35
36 An error message such as "dbmi: Protocol error" either
37 indicates an invalid column name or an unsupported column
38 type (then the GRASS SQL parser needs to be extended).
39
40 DBF column names are limited to 10 characters (DBF API
41 definition)
42
44 Display all vector points except for LAMAR valley and extensive trap‐
45 ping (brackets are superfluous in this example):
46 d.vect trapping_sites_points fcol=black icon=basic/diamond col=white
47 size=13 \
48 where="valley <> 'LAMAR' OR (valley = 'LAMAR' AND description =
49 'extensive trapping')"
50
51
52 Select all attributes from table where str1 column values are not 'No
53 Name':
54 echo "SELECT * FROM archsites WHERE str1 <> 'No Name'" | db.select
55
56
57 Example of subquery expressions from a list (does not work for DBF
58 driver):
59 v.db.select mysites where="id IN ('P04', 'P05')"
60
61
62 Example of pattern matching (does not work for DBF driver):
63 # match exactly number of characters (here: 2):
64 v.db.select mysites where="id LIKE 'P__'"
65 #define wildcard:
66 v.db.select mysites where="id LIKE 'P%'"
67
68
69 Example of null handling:
70 v.db.addcol map=roads col="nulltest int"
71 v.db.update map=roads col=nulltest value=1 where="cat > 2"
72 d.vect roads where="nulltest is null"
73 v.db.update map=roads col=nulltest value=2 where="cat <= 2"
74
75
76 Examples of complex expressions in updates (using v.db.* modules):
77 v.db.addcol map=roads col="exprtest double precision"
78 v.db.update map=roads col=exprtest value=cat/nulltest
79 v.db.update map=roads col=exprtest value=cat/nulltest+cat where=cat=1
80
81
82 Examples of complex expressions in updates (using db.* modules):
83 echo "UPDATE roads SET exprtest=null"
84 echo "UPDATE roads SET exprtest=cat/2" | db.execute
85 echo "UPDATE roads SET exprtest=cat/2+cat/3" | db.execute
86 echo "UPDATE roads SET exprtest=NULL WHERE cat>2" | db.execute
87 echo "UPDATE roads SET exprtest=cat/3*(cat+1) WHERE exprtest IS NULL" |
88 db.execute"
89
90
91 Instead of creating and updating new columns with an expression, you
92 can use the expression directly in a command:
93 d.vect roads where="(cat/3*(cat+1))>8"
94 d.vect roads where="cat>exprtest"
95
96
98 Database management in GRASS GIS,
99 Help pages for database modules,
100 SQL Guide and Reference (Red Hat)
101
102 Last changed: $Date: 2006/08/24 19:11:36 $
103 Help Index
104
105
106
107GRASS 6.2.2 sql(1)