1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
<h2>DESCRIPTION</h2>
<em>db.select</em> prints result of selection from database based on
SQL statement read from input file or from standard input to standard
output. Each individual query has to be written on one single line and
different queries have to be written on separate lines.
<h2>NOTE</h2>
If parameters for database connection are already set with
<em><a href="db.connect.html">db.connect</a></em>, they are taken as
default values and do not need to be specified each time. Output will
be displayed to standard output or can be directed to a file
(option <b>output</b>).
<h2>EXAMPLES</h2>
<h3>Basic usage</h3>
<div class="code"><pre>
db.select sql="select * from roads"
</pre></div>
or
<div class="code"><pre>
echo "select * from roads" | db.select input=-
</pre></div>
or
<div class="code"><pre>
db.select input=file.sql
</pre></div>
or
<div class="code"><pre>
cat file.sql | db.select input=-
</pre></div>
<p>
Select all from table roads:
<div class="code"><pre>
db.select -c driver=odbc database=mydb table=hospitals \
input=file.sql output=result.csv
</pre></div>
<p>
Select some string attribute, exclude others:
<div class="code"><pre>
db.select sql="SELECT * FROM archsites WHERE str1 <> 'No Name'"
</pre></div>
<p>
Select some string attribute with ZERO length:
<div class="code"><pre>
db.select sql="SELECT * FROM archsites WHERE str1 IS NULL"
</pre></div>
<p>
Select coordinates from PostGIS table:
<div class="code"><pre>
db.select sql="SELECT x(geo),y(geo) FROM localizzazione"
</pre></div>
<h3>Execute multiple SQL statements</h3>
<div class="code"><pre>
cat file.sql
SELECT * FROM busstopsall WHERE cat = 1
SELECT cat FROM busstopsall WHERE cat > 4 AND cat < 8
db.select input=file.sql
</pre></div>
<p>
<h3>Count number of cases falling into same position</h3>
When multiple observation have the spatial coordinates, they can still
be counted (if needed, coordinates can be uploaded to the attribute
table by <em>v.to.db</em>:
<div class="code"><pre>
db.select sql="SELECT long,lat,site_id,department,obs,COUNT(long) as count_cases \
FROM diseases GROUP BY long,lat"
</pre></div>
<h2>SEE ALSO</h2>
<em>
<a href="db.connect.html">db.connect</a>,
<a href="db.describe.html">db.describe</a>,
<a href="db.drivers.html">db.drivers</a>,
<a href="db.droptable.html">db.droptable</a>,
<a href="db.execute.html">db.execute</a>,
<a href="db.login.html">db.login</a>,
<a href="db.tables.html">db.tables</a>
</em>
<p>
<em>
<a href="sql.html">GRASS SQL interface</a>
</em>
<h2>AUTHORS</h2>
Original author unknown (probably CERL)<br>
Modifications by Radim Blazek, ITC-Irst, Trento, Italy<br>
Support for multiple statements by Martin Landa, Czech Technical University in Prague
|