db.select(1grass)

πŸ’– NAME πŸ’–

okay bestie, meet db.select β€” she's the one from the db.select(1grass) page and she is so iconic, no cap.

  • Selects data from attribute table.
  • Performs SQL query statement(s). ✨

πŸŽ€ 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]   [format=name]
[output=name]   [--overwrite]  [--help]  [--verbose]  [--quiet]  [--ui]

🚩 Flags β€” the lil toggles 🚩

  • -c β€” Do not include column names in output
  • -d β€” Describe query only (don't run it)
  • -v β€” Vertical output instead of horizontal [deprecated] β€” bestie, it's giving retired πŸ’€ use format=vertical instead.
  • -t β€” Only test query, do not execute
  • --overwrite β€” Allow output files to overwrite existing files
  • --help β€” Print usage summary
  • --verbose β€” Verbose module output
  • --quiet β€” Quiet module output
  • --ui β€” Force launching GUI dialog

🌸 Parameters β€” the real main characters 🌸

  • sql=sql_query β€” SQL SELECT statement Example: select * from towns where population > 10000
  • input=name β€” Name of file containing SQL select statement(s); '-' for standard input
  • table=name β€” Name of table to query
  • driver=name β€” Name of database driver Options: dbf, 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
  • vertical_separator=character β€” Vertical record separator (requires -v flag [deprecated] or format=vertical) Special characters: pipe, comma, space, tab, newline
  • null_value=string β€” String representing NULL value
  • format=name β€” Output format Options: plain, csv, json, vertical plain: Configurable plain text output csv: CSV (Comma Separated Values) json: JSON (JavaScript Object Notation) vertical: Plain text vertical output (instead of horizontal)
  • output=name β€” Name for output file (if omitted or "-" output to stdout)

πŸ’« DESCRIPTION πŸ’«

okay so here's the vibe: db.select prints result of selection from database based on SQL statement read from input file or from standard input to standard output. That's the whole gig. And the ✨ one rule ✨ you cannot break: each individual query has to be written on one single line, and different queries have to be written on separate lines. No wrapping, no freestyling, she will not read your multi-line poetry. πŸ“


πŸ“Œ 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 β€” yes queen, set it once and chill. 🫢 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"

πŸ”— SEE ALSO πŸ”—

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

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)

Latest change: Saturday Dec 27 00:12:20 2025 in commit: 2a7fe23c50574a096f599cd43436ae45178bf96d

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

Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual


okay that's the whole page bestie, you ate πŸ’… this little masterpiece shipped under GRASS 8.5.0 (that's the version and the manual name up top, db.select(1grass), in case you were wondering where the header went πŸŽ€), and the last touch-up landed Saturday Dec 27 00:12:20 2025 β€” so yeah, fresh. go query something iconic. πŸ¦‹βœ¨

πŸ“¦ where this page comes from