db.select(1grass)

db.select1grass

Selects data from attribute table. performs sql query statement(s).

Usage

db.select

db.select --help

db.select [-cdvt] [sql=sql_query] [input=name] [table=name] [driver=name] [database=name] [separator=character] [vertical_separator=character] [null_value=string] [output=name] [--overwrite] [--help] [--verbose] [--quiet] [--ui]

Keywords

database, attribute table, SQL

Overview

db.select 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.

Note

If parameters for database connection are already set with db.connect, 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 output).

Examples

Basic usage

db.select sql="select * from roads"

or

echo "select * from roads" | db.select input=-

or

db.select input=file.sql

or

cat file.sql | db.select input=-

Select all from table roads:

db.select -c driver=odbc database=mydb table=hospitals \
          input=file.sql output=result.csv

Select some string attribute, exclude others:

db.select sql="SELECT * FROM archsites WHERE str1 <> ’No Name’"

Select some string attribute with ZERO length:

db.select sql="SELECT * FROM archsites WHERE str1 IS NULL"

Select coordinates from PostGIS table:

db.select sql="SELECT x(geo),y(geo) FROM localizzazione"

Execute multiple SQL statements

cat file.sql
SELECT * FROM busstopsall WHERE cat = 1
SELECT cat FROM busstopsall WHERE cat > 4 AND cat < 8
db.select input=file.sql

Count number of cases falling into same position

When multiple observation have the spatial coordinates, they can still be counted (if needed, coordinates can be uploaded to the attribute table by v.to.db:

db.select sql="SELECT long,lat,site_id,department,obs,COUNT(long) as count_cases \
               FROM diseases GROUP BY long,lat"

Source code

Available at: db.select source code (history)

Accessed: Monday Feb 24 17:50:23 2025

Main index | Database index | Topics index | Keywords index | Graphical index | Full index

© 2003-2025 GRASS Development Team, GRASS GIS 8.4.1 Reference Manual

Releases

10 releases since Debian 4.0 (Etch); the text changed 9 times.

  1. 4.0
  2. 5.0
  3. 6.0
  4. 7
  5. 8
  6. 9
  7. 10
  8. 11
  9. 12
  10. 13

Authors

Original author unknown (probably CERL)
Modifications by Radim Blazek, ITC-Irst, Trento, Italy
Support for multiple statements by Martin Landa, Czech Technical University in Prague

From grass-doc 8.4.1-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.