Forming Expressions

Expressions are composed of a combination of data values and operators.

Data values may be specified as constants (literal values), or retrieved from a database. Database values are specified by using the name of the data column. The name must be specified exactly as recorded in the DBMS. Database columns names are case-sensitive, and AREA will refer to a different column than Area.

[Important]Important

Many simple DBMS store column names in upper case, but unfortunately some applications (e.g. ArcView 3.2) display column names with a different capitalization than is actually stored in the database. Care must be taken to identify columns correctly.

Operators are applied to data values, or combine several data values (e.g. "1 + 1"). When an expression contains multiple operators the operators are applied in sequence according to a standard set of rules of operator precedence. Table 2 lists the available operators. These are listed in order of precedence (for example, in the expression "1 + 2 * 3" the multiplication will occur before the addition). Where several identical operators occur in a row they are evaluated from left to right. Parentheses may be used to explicitly control the order of evaluation (e.g. "(1 + 2) * 3").

Some of the operators have several aliases. For example the relational 'less than' operator can be represented by the symbols 'lt' or '<'. There is no difference between these two usages. Capitalization does not matter in operator symbols ('AND' is the same as 'And').

An expression may be composed of several sub-expressions, each separated by the semicolon (;) character. The sub-expressions will be evaluated in sequence, and the returned value of the expression will be the value of the final sub-expression. Values produced by the initial sub-expressions will be discarded, however these sub-expressions may have side effects (e.g. the setVar() function) that influence subsequent sub-expressions.

OperatorSyntaxDescriptionResult

Logical 'or'

<bool> or <bool>

<bool> || <bool>

The logical 'or' operator combines two boolean operands. The results is 'true' if either operand evaluates to 'true'.

<bool>

Logical 'and'

<bool> and <bool>

<bool> && <bool>

The logical 'and' operator combines two boolean operands. The results is 'true' only if both operands evaluate to 'true'.

<bool>

Binary 'or'

<int> | <int>

The binary 'or' operator combines the bit fields in two integers using an 'or' operation. The result is always an integer.

<int>

Binary 'xor'

<int> ^ <int>

The binary 'exclusive or' operator combines the bit fields in two integers using an 'xor' operation. The result is always an integer.

<int>

Binary 'and'

<int> & <int>

The binary 'and' operator combines the bit fields in two integers using an 'and' operation. The result is always an integer.

<int>

Equality

<value> = <value>

<value> == <value>

<value> eq <value>

The equality operator performs a test to see if the two operands are equal. The result is always a boolean.

<bool>

Inequality

<value> != <value>

<value> ne <value>

The inequality operator performs a test to see if the two operands are not equal. The result is always a boolean.

<bool>

in

<string> in <string>

The right operand is assumed to be a comma-separated list of string values (e.g. 'A,B,C'). The 'in' operator will test to see if the left operand is equal to any of the values in the right hand list. If an exact match is found the result will be true, otherwise false.

<bool>

Relational

<value> op <value>

where op can be:

< or 'lt'

<= or 'le'

> or 'gt'

>= or 'ge'

Compare two values using a relational operator. The values may be both strings (in which case a lexicographical comparison is made), both integers (an integer comparison is made), or a combination of integers and numbers (automatic type promotion occurs and the numbers are compared).

<bool>

Bit shift

<int> >> <int>

<int> << <int>

<int> >>> <int>

These operators implement bit operations for logical shift right '>>>', signed shift right '>>' and shift left '<<'. The value on the left is the bit field to be shifted, and the value on the right is the amount of the shift. These operators always return an integer bitfield.

<int>

Concatenation

<string> + <value>

The string values of the two operands are concatenated together. If one of the operands is not a string value, it will undergo automatic promotion to a string.

<string>

Summation

<value> + <value>

<value> - <value>

Add or subtract two values. If both values are integers the result will be an integer. If one of both of the values is a number the result will be a number.

<int> or <number>

Product

<value> * <value>

<value> / <value>

<value> % <value>

Multiple, divide or modulo two values. If both values are integers the result will be an integer. If one of both of the values is a number the result will be a number.

<int> or <number>

Negation

- <integer>

- <number>

Returns the negative of the original value.

<int> or <number>

Logical Not

not <bool>

! <bool>

Performs a logical not operation on a boolean value. If the operand is true, the result will be false. If the operand is false, the result will be true.

<bool>

Bitwise Compliment

~ <integer>

Performs a bitwise complement operation. The result will always be an integer.

<integer>