db.select.html 2.6 KB

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