db.select(1)

πŸ’Ύ db.select β€” the GRASS GIS bestie manual πŸ’Ύ

ok so you opened the manual for db.select, which lives in the GRASS GIS User's Manual and is page db.select(1). she's a database girlie. let's get into it 🫢


✨ NAME ✨

db.select β€” selects data from an attribute table. she performs SQL query statement(s), plural, yes ma'am πŸ’…

🏷️ KEYWORDS 🏷️

database, attribute table, SQL


🌸 SYNOPSIS 🌸

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]

πŸŽ€ Flags πŸŽ€

  • -c β€” do NOT include column names in the output. just the vibes, no labels.
  • -d β€” describe the query only, don't actually run it. window shopping fr.
  • -v β€” vertical output instead of horizontal. she's standing up now πŸ’…
  • -t β€” only test the query, do not execute. a vibe check, not a full send.
  • --overwrite β€” allow output files to overwrite files that already exist. yes she will eat your old file, be careful bestie 😭
  • --help β€” print usage summary. your lil cheat sheet ✨
  • --verbose β€” verbose module output. she will NOT stop talking and honestly? iconic.
  • --quiet β€” quiet module output. she's giving mystery, she's giving silence 🀫
  • --ui β€” force launching the GUI dialog. for the girlies who like buttons πŸ–±οΈ

πŸ¦‹ Parameters πŸ¦‹

  • sql=sql_query β€” an SQL SELECT statement. Example: select * from towns where population > 10000
  • input=name β€” name of file containing SQL select statement(s). use '-' for standard input.
  • table=name β€” name of table to query.
  • driver=name β€” name of database driver. Options: dbf, mesql, mysql, odbc, ogr, pg, sqlite Default: sqlite
  • database=name β€” name of database. Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
  • separator=character β€” field separator. Special characters: pipe, comma, space, tab, newline Default: pipe
  • vertical_separator=character β€” vertical record separator (this one REQUIRES the -v flag, no -v no separator, that's the rule πŸ’€). Special characters: pipe, comma, space, tab, newline
  • null_value=string β€” string representing a NULL value.
  • output=name β€” name for output file (if omitted or "-" it goes to stdout).

πŸ’– DESCRIPTION πŸ’–

db.select prints the result of a selection from the database, based on an SQL statement read from an input file or from standard input, and sends it to standard output. no cap.

ok but the rule, and it is a strict rule: each individual query has to be written on one single line, and different queries have to be written on separate lines. one line per query, bestie, don't fight it 🫢

πŸ“Œ NOTE πŸ“Œ

if the parameters for the database connection are already set with db.connect, they get taken as default values and you do not need to specify them every single time like a tryhard. the output will be displayed to standard output, or you can direct it to a file with the output option. queen behavior ✨


🌈 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 a 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 observations have the same spatial coordinates, they can still be counted (and if you need them, the 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"

πŸ‘€ SEE ALSO πŸ‘€

db.connect, db.describe, db.drivers, db.droptable, db.execute, db.login, db.tables

the GRASS SQL interface

πŸ‘‘ 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

🧚 SOURCE CODE 🧚

Available at: db.select source code (history)

Accessed: Saturday Jan 17 05:40:34 2026

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

Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual


and that's the whole page bestie, we ate and left absolutely no crumbs πŸ’…βœ¨

ok so before you go: this whole thing is GRASS 8.4.2 β€” that's the version, and it was the db.select(1) page from that reference manual, accessed Saturday Jan 17 05:40:34 2026. the manual itself is Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual. go query something cute πŸ¦‹πŸ’–

πŸ“¦ where this page comes from