For example, if you want to select only those records from the table well where the value for depth is either 58 or 75 the following could be entered:
To select all wells in an area where the value for well is between 50 and 120:
To select all wells of depth greater than 75 where the value for owner is not equal to SMITH:
If the database column used as the selection criteria is a character field then the associated value must be placed in double quotes. To determine the data types associated with columns in the currently selected database use the g.column.pg command with the -v flag.
In addition to the operators presented in the examples above a range of relational operators including and, or, etc. are supported. There may be some differences in the relational operators which are supported with different database drivers.
The examples presented above were created using the command line parser. If d.site.pg is being called from a shell script remember to escape quoted strings. The follwing example presents a component of a shell script used to join two tables and display vector features where the database column ad.pgo is set to "NONE".
Queries which are more complex than these are best implemented using the -s flag and a prepared postQUEL file.
For instance, assume that well is a table containing X,Y coordinate values and that wellowners is a table containing ownership.pgormation associated with well logs. To base a query on site location which would return attribute data on ownership and locational.pgormation in the table well the following join would be needed on the command line:
The column wellid is common to both the well and the wellowners table. Because of this attribute data from both tables will be returned if the coordinates registered by the mouse return a record from the table well within a radius specified by the distance parameter on the command line. Specifying these conditions would insure that all rows from table roads which satisfy the query criteria would be matched with the corresponding rows in table main, which are then related to the spatial features in the GRASS data layer via the GRASS category values.
This syntax is adequate to accomplish 2 table joins. However, if the query demands joins between more than 2 tables it is advisable to use the -s option [see Alternate Command Line Usage] to read a user prepared query, complete with join requirements, from a file.
The user must also specify the name of the GRASS data layer containing these category values on the command line. The following example illustrates the syntax which must be used in constructing a retrieve statement for use with the -s flag.
Postgres modifications: Janne Soimasuo, Faculty of Forestry, University of Joensuu, Finland.
Updated to GRASS 5 by Alex Shevlakov (sixote@yahoo.com)