To select all cfcclookup.codes the value for cfcclookup.code is of cfcc type A (ie. roads):
To select all cfcclookup.codes except those for roads:
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.vect.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 cfcclookup.classname is set to "Divided" (eg. all tiger features identified as divided highways).
Queries which are more complex than these are best implemented using the -s flag and a prepared postQUEL file.
For instance, assume that feature is a table containing column values (recordnum), associated with category values in a GRASS vector file. In addition, assume that cfcclookup.cfcccodes is a table containing attribute data on the transportation network in the same area. In this example recordnum is the column linking feature to the GRASS category file and cfcclookup.cfcc is the column linking cfcclookup with the feature. To specify a query based on attribute values in the table cfcclookup.cfcccodes the join statement would be:
Specifying these conditions would insure that all rows from table cfcclookup which satisfy the query criteria would be matched with the corresponding rows in table feature, which are then related to the spatial features in the GRASS data layer via the database column feature.recordnum which is related to 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)