1db.select(1) Grass User's Manual db.select(1)
2
3
4
6 db.select - Selects data from attribute table.
7 Performs SQL query statement(s).
8
10 database, attribute table, SQL
11
13 db.select
14 db.select --help
15 db.select [-cdvt] [sql=sql_query] [input=name] [table=name]
16 [driver=name] [database=name] [separator=character] [verti‐
17 cal_separator=character] [null_value=string] [output=name]
18 [--overwrite] [--help] [--verbose] [--quiet] [--ui]
19
20 Flags:
21 -c
22 Do not include column names in output
23
24 -d
25 Describe query only (don’t run it)
26
27 -v
28 Vertical output (instead of horizontal)
29
30 -t
31 Only test query, do not execute
32
33 --overwrite
34 Allow output files to overwrite existing files
35
36 --help
37 Print usage summary
38
39 --verbose
40 Verbose module output
41
42 --quiet
43 Quiet module output
44
45 --ui
46 Force launching GUI dialog
47
48 Parameters:
49 sql=sql_query
50 SQL SELECT statement
51 Example: select * from towns where population > 10000
52
53 input=name
54 Name of file containing SQL select statement(s)
55 ’-’ for standard input
56
57 table=name
58 Name of table to query
59
60 driver=name
61 Name of database driver
62 Options: dbf, mesql, mysql, odbc, ogr, pg, sqlite
63 Default: sqlite
64
65 database=name
66 Name of database
67 Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
68
69 separator=character
70 Field separator
71 Special characters: pipe, comma, space, tab, newline
72 Default: pipe
73
74 vertical_separator=character
75 Vertical record separator (requires -v flag)
76 Special characters: pipe, comma, space, tab, newline
77
78 null_value=string
79 String representing NULL value
80
81 output=name
82 Name for output file (if omitted or "-" output to stdout)
83
85 db.select prints result of selection from database based on SQL state‐
86 ment read from input file or from standard input to standard output.
87 Each individual query has to be written on one single line and differ‐
88 ent queries have to be written on separate lines.
89
91 If parameters for database connection are already set with db.connect,
92 they are taken as default values and do not need to be specified each
93 time. Output will be displayed to standard output or can be directed to
94 a file (option output).
95
97 Basic usage
98 db.select sql="select * from roads"
99 or
100 echo "select * from roads" | db.select input=-
101 or
102 db.select input=file.sql
103 or
104 cat file.sql | db.select input=-
105
106 Select all from table roads:
107 db.select -c driver=odbc database=mydb table=hospitals \
108 input=file.sql output=result.csv
109
110 Select some string attribute, exclude others:
111 db.select sql="SELECT * FROM archsites WHERE str1 <> ’No Name’"
112
113 Select some string attribute with ZERO length:
114 db.select sql="SELECT * FROM archsites WHERE str1 IS NULL"
115
116 Select coordinates from PostGIS table:
117 db.select sql="SELECT x(geo),y(geo) FROM localizzazione"
118
119 Execute multiple SQL statements
120 cat file.sql
121 SELECT * FROM busstopsall WHERE cat = 1
122 SELECT cat FROM busstopsall WHERE cat > 4 AND cat < 8
123 db.select input=file.sql
124
125 Count number of cases falling into same position
126 When multiple observation have the spatial coordinates, they can still
127 be counted (if needed, coordinates can be uploaded to the attribute ta‐
128 ble by v.to.db:
129 db.select sql="SELECT long,lat,site_id,department,obs,COUNT(long) as count_cases \
130 FROM diseases GROUP BY long,lat"
131
133 db.connect, db.describe, db.drivers, db.droptable, db.execute,
134 db.login, db.tables
135
136 GRASS SQL interface
137
139 Original author unknown (probably CERL)
140 Modifications by Radim Blazek, ITC-Irst, Trento, Italy
141 Support for multiple statements by Martin Landa, Czech Technical Uni‐
142 versity in Prague
143
145 Available at: db.select source code (history)
146
147 Main index | Database index | Topics index | Keywords index | Graphical
148 index | Full index
149
150 © 2003-2019 GRASS Development Team, GRASS GIS 7.8.2 Reference Manual
151
152
153
154GRASS 7.8.2 db.select(1)