~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to lib/db/sqlp/description.html

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
 
<html>
3
 
<head>
4
 
<title>SQL support in GRASS GIS</title>
5
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6
 
<link rel="stylesheet" href="grassdocs.css" type="text/css">
7
 
</head>
8
 
 
9
 
<!-- This file is lib/db/sqlp/description.html -->
10
 
 
11
 
<body bgcolor="white">
12
 
 
13
 
<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
14
 
 
15
 
<H2>SQL support in GRASS GIS</H2>
16
 
 
17
 
GRASS can use various RDBMS and embedded databases. 
18
 
SQL queries are directly passed to the underlying 
19
 
database system. 
20
 
The set of supported SQL commands depends on the RDMBS 
21
 
and driver selected.  
22
 
 
23
 
<H2>Drivers</H2>  
24
 
The list of available drivers can vary in various binary 
25
 
distributions of GRASS. 
26
 
<p>
27
 
 
28
 
<table border=1 >
29
 
<tr><td><a href="grass-dbf.html">dbf</a></td><td>DBF files. Data are stored in DBF files.</td>
30
 
<td><a href="http://shapelib.maptools.org/dbf_api.html">http://shapelib.maptools.org/dbf_api.html</a></td></tr>
31
 
 
32
 
<tr><td><a href="grass-sqlite.html">sqlite</a></td><td>SQLite embedded database.</td>
33
 
<td><a href="http://sqlite.org/">http://sqlite.org/</a></td></tr>
34
 
 
35
 
<tr><td><a href="grass-pg.html">pg</a></td><td>PostgreSQL RDBMS.</td>
36
 
<td><a href="http://postgresql.org/">http://postgresql.org/</a></td></tr>
37
 
 
38
 
<tr><td><a href="grass-mysql.html">mysql</a></td><td>MySQL RDBMS.</td>
39
 
<td><a href="http://mysql.org/">http://mysql.org/</a></td></tr>
40
 
 
41
 
<tr><td><a href="grass-mesql.html">mesql</a></td><td>MySQL embedded database.</td>
42
 
<td><a href="http://mysql.org/">http://mysql.org/</a></td></tr>
43
 
 
44
 
<tr><td><a href="grass-odbc.html">odbc</a></td><td>UnixODBC. (PostgreSQL, Oracle, etc.)</td>
45
 
<td><a href="http://www.unixodbc.org/">http://www.unixodbc.org/</a></td></tr>
46
 
 
47
 
</table>
48
 
 
49
 
 
50
 
<H2>NOTES</H2>
51
 
 
52
 
<ul>
53
 
<li> SQL does not support '.' (dots) in table names.
54
 
<li> Supported table name characters are only:<br>
55
 
    [A-Za-z][A-Za-z0-9_]*
56
 
<li> A table name must start with a character, not a number.
57
 
<li> Text-string matching requires the text part to be 'single quoted'.
58
 
When run from the command line multiple queries should be contained 
59
 
in "double quotes". e.g.<br>
60
 
<div class="code"><pre>
61
 
d.vect map where="individual='juvenile' and area='beach'"
62
 
</pre></div>
63
 
<li> An error message such as "dbmi: Protocol error" either indicates an invalid column name
64
 
     or an unsupported column type (then the GRASS SQL parser needs to be extended).
65
 
<li> DBF column names are limited to 10 characters (DBF API definition)
66
 
</ul>
67
 
 
68
 
 
69
 
<h2>EXAMPLES</h2>
70
 
 
71
 
Display all vector points except for LAMAR valley and <i>extensive trapping</i> (brackets are superfluous in this example):
72
 
<div class="code"><pre>
73
 
d.vect trapping_sites_points fcol=black icon=basic/diamond col=white size=13 \
74
 
    where="valley <> 'LAMAR' OR (valley = 'LAMAR' AND description = 'extensive trapping')"
75
 
</pre></div>
76
 
 
77
 
<p>
78
 
Select all attributes from table where str1 column values are not 'No Name':
79
 
<div class="code"><pre>
80
 
echo "SELECT * FROM archsites WHERE str1 &lt;&gt; 'No Name'" | db.select
81
 
</pre></div>
82
 
<p>
83
 
 
84
 
 
85
 
<p><b>Example</b> of subquery expressions from a list (does not work for DBF driver):
86
 
<div class="code"><pre>
87
 
v.db.select mysites where="id IN ('P04', 'P05')"
88
 
</pre></div>
89
 
 
90
 
 
91
 
<p><b>Example</b> of pattern matching:
92
 
<div class="code"><pre>
93
 
 
94
 
# field contains string:
95
 
#  for DBF driver:
96
 
v.extract rivers out=rivers_noce where="DES LIKE 'NOCE'"
97
 
#  for SQLite driver:
98
 
v.extract rivers out=rivers_noce where="DES LIKE '%NOCE%'"
99
 
 
100
 
# match exactly number of characters (here: 2), does not work for DBF driver:
101
 
v.db.select mysites where="id LIKE 'P__'"
102
 
 
103
 
#define wildcard:
104
 
v.db.select mysites where="id LIKE 'P%'"
105
 
</pre></div>
106
 
 
107
 
<p><b>Example</b> of null handling:
108
 
<div class="code"><pre>
109
 
v.db.addcol map=roads col="nulltest int"
110
 
v.db.update map=roads col=nulltest value=1 where="cat &gt; 2"
111
 
d.vect roads where="nulltest is null"
112
 
v.db.update map=roads col=nulltest value=2 where="cat &lt;= 2"
113
 
</pre></div>
114
 
 
115
 
 
116
 
<p><b>Examples</b> of complex expressions in updates (using v.db.* modules):
117
 
<div class="code"><pre>
118
 
v.db.addcol map=roads col="exprtest double precision"
119
 
v.db.update map=roads col=exprtest value=cat/nulltest
120
 
v.db.update map=roads col=exprtest value=cat/nulltest+cat where=cat=1
121
 
</pre></div>
122
 
 
123
 
 
124
 
<p><b>Examples</b> of complex expressions in updates (using db.* modules):
125
 
<div class="code"><pre>
126
 
echo "UPDATE roads SET exprtest=null"
127
 
echo "UPDATE roads SET exprtest=cat/2" | db.execute
128
 
echo "UPDATE roads SET exprtest=cat/2+cat/3" | db.execute
129
 
echo "UPDATE roads SET exprtest=NULL WHERE cat&gt;2" | db.execute
130
 
echo "UPDATE roads SET exprtest=cat/3*(cat+1) WHERE exprtest IS NULL" | db.execute"
131
 
</pre></div>
132
 
 
133
 
 
134
 
<p>
135
 
Instead of creating and updating new columns with an expression,
136
 
you can use the expression directly in a command:
137
 
<div class="code"><pre>
138
 
d.vect roads where="(cat/3*(cat+1))&gt;8"
139
 
d.vect roads where="cat&gt;exprtest"
140
 
</pre></div>
141
 
 
142
 
 
143
 
<p><b>Example</b> of changing a SQL type (type casting, does not work for DBF driver):
144
 
<div class="code"><pre>
145
 
# North Carolina data set: convert string column to double precision
146
 
#  copy map into current mapset
147
 
g.copy vect=geodetic_pts,mygeodetic_pts
148
 
v.db.addcol mygeodetic_pts col="zval double precision"
149
 
 
150
 
# the 'z_value' col contains 'N/A' strings, not to be converted
151
 
v.db.update mygeodetic_pts col=zval \
152
 
            qcol="CAST(z_value AS double precision)" \
153
 
            where="z_value <> 'N/A'"
154
 
</pre></div>
155
 
 
156
 
<h2>SEE ALSO</h2>
157
 
 
158
 
<a href="databaseintro.html">Database management in GRASS GIS</a>,<BR>
159
 
<a href="database.html">Help pages for database modules</a>,<BR>
160
 
<a href=http://www.redhat.com/docs/manuals/database/RHDB-2.1-Manual/sql/sqlreference.html>SQL
161
 
    Guide and Reference</a> (Red Hat)
162
 
 
163
 
 
164
 
<p><i>Last changed: $Date: 2009-06-01 16:15:34 +0200 (Mon, 01 Jun 2009) $</i></p>
165
 
<HR>
166
 
<BR><a href=index.html>Help Index</a>
167
 
<P>&copy; 2008 <a href="http://grass.osgeo.org">GRASS Development Team</a></P>
168
 
</body>
169
 
</html>