WhereClause

AMD: require(["esri/core/sql/WhereClause"], (WhereClause) => { /* code goes here */ });
ESM: import WhereClause from "@arcgis/core/core/sql/WhereClause.js";
Object: esri/core/sql/WhereClause
Since: ArcGIS Maps SDK for JavaScript 4.14

The WhereClause is used to extract the features that meet a specified condition by parsing the provided results in to a value. The sql.parseWhereClause() method returns a Promise that resolves to an instance of this module.

Property Overview

Name Type Summary Object
String[]

An array of the field names used in the where clause.

WhereClause
Boolean

Returns true if the parsed where clause meets the requirements of standardized sql.

WhereClause
SQLNode

A parse tree is a data structure for representing a parsed sql statement.

WhereClause

Property Details

fieldNames

Property
fieldNames String[]

An array of the field names used in the where clause. It can be used to get the appropriate fields when querying layers.

Example
// parse layer's definition expression into where clause object
sql.parseWhereClause(layer.definitionExpression, layer.fieldsIndex)
.then(function(clause){
  layer.queryFeatures({
    where: "1=1",
    // where clause object returns layer fields
    // use these fields to query features from the layer
    outFields: clause.fieldsNames
  }).then(function(results) {
   // process query results
  });
});

isStandardized

Property
isStandardized Booleanreadonly

Returns true if the parsed where clause meets the requirements of standardized sql.

parseTree

Property
parseTree SQLNode
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, parseTree added at 4.24.

A parse tree is a data structure for representing a parsed sql statement. Parsing a statement requires the grammar of the language that the statement was written.

Method Overview

Name Return Type Summary Object
Object

Executes the where clause against a feature to generate a value.

WhereClause
Boolean

Tests the attributes of a feature against the whereClause, and returns true if the test passes, false otherwise.

WhereClause

Method Details

calculateValue

Method
calculateValue(feature){Object}

Executes the where clause against a feature to generate a value. It is used when the WhereClause is being used as a simple expression. For example, you can use the expression to gather values for statistics.

Parameter
feature Object

The feature to check against the where clause.

Returns
Type Description
Object Returns a value after check feature against the provided where clause. Returns null if the provided value is unknown.
Example
// calculate the grand total sales price of all features
featureLayer.queryFeatures().then(function(results){
  let total;
  const expression = "totalSales * totalPrice";
  sql.parseWhereClause(expression, layer.fieldsIndex)
  .then(function(whereClause){
    // check if the where clause meets requirements of standardized sql
    if (whereClause.isStandardized){
      features.forEach(function(feature){
        total += whereClause.calculateValue(feature)
      });
      console.log(total); // prints the total sales price of all features
    }
  });
});

testFeature

Method
testFeature(feature){Boolean}

Tests the attributes of a feature against the whereClause, and returns true if the test passes, false otherwise.

Parameter
feature Object

The feature to test against the whereClause.

Returns
Type Description
Boolean Returns true if the test passes, false otherwise.
Example
sql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex)
.then(function(clause){
  let testResult = clause.testFeature(new Graphic({
    attributes: {
      POPULATION: 300000
   }
 });
 console.log(testResult); // prints true
});

Type Definitions

BinaryNode

Type Definition
BinaryNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, BinaryNode added at 4.24.

A binary expression node. It is an operator that defines the way two expressions are combined to yield a single result. It can be an arithmetic operator, the assignment operator (=), a comparison operator (>=), a logical operator (AND), or a string concatenation operator (+).

Properties
type String

The value is always "binary-expression".

operator String

Defines the way two expressions are combined to yield a single result.

Possible Values:"AND"|"OR"|"IS"|"ISNOT"|"IN"|"NOT IN"|"BETWEEN"|"NOTBETWEEN"|"LIKE"|"NOT LIKE"|"<>"|"<"|">"|">="|"<="|"="|"*"|"-"|"+"|"/"

left SQLNode

SQL node to the left of the binary node.

right SQLNode

SQL node to the right of the binary node.

escape String
optional

Escape string.

BoolNode

Type Definition
BoolNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, BoolNode added at 4.24.

A node that contains a boolean expression. Used for expressing a condition or criterion which can be either true or false.

Properties
type String

The value is always "boolean".

value Boolean

Values are true or false.

ColumnNode

Type Definition
ColumnNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, ColumnNode added at 4.24.

A node that contains column name of a layer or table.

Properties
type String

The value is always "column-reference".

column String

Column or field name.

The value is always "string".

CurrentTimeNode

Type Definition
CurrentTimeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, CurrentTimeNode added at 4.24.

A node that contains CURRENT_TIME or CURRENT_DATE functions.

Properties
type String

The value is always "current-time".

mode String

The current time node mode.

Possible Values:"timestamp"|"date"

DateNode

Type Definition
DateNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, DateNode added at 4.24.

A node that contains date.

Properties
type String

The value is always "date".

value String

The date value.

FunctionNode

Type Definition
FunctionNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, FunctionNode added at 4.24.

A nodes that contains SQL function.

Properties
type String

The value is always "function".

name String

Name of the SQL function.

args ListNode

Function arguments.

IntervalNode

Type Definition
IntervalNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, IntervalNode added at 4.24.

Interval node indicates that the character literal is an interval. An interval is defined as the difference between two dates and times.

Properties
type String

The value is always "interval".

value StringNode

Interval node value.

op String

Interval node sign.

Possible Values:"+"|"-"|""

The interval qualifier can either be a single datetime field or be composed of two datetime fields, in the form: TO .

IntervalPeriodNode

Type Definition
IntervalPeriodNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, IntervalPeriodNode added at 4.24.

Interval period node.

Properties
type String

The value is always "interval-period".

period String

Interval node periods.

Possible Values:"day"|"month"|"hour"|"second"|"year"|"minute"

precision Number
secondary String

The value is always "number".

IntervalQualifierNode

Type Definition
IntervalQualifierNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, IntervalQualifierNode added at 4.24.

Node that contains interval qualifier. The interval qualifier can either be a single datetime field or be composed of two datetime fields, in the form: <leading field> TO <trailing field>.

Properties
type String

The value is always "interval-qualifier".

period String

Interval node periods.

Possible Values:"day"|"month"|"hour"|"second"|"year"|"minute"

precision Number

Precision for an interval data type includes interval leading precision, interval precision, and seconds precision.

secondary String

Seconds precision.

The value is always "number".

ListNode

Type Definition
ListNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, ListNode added at 4.24.

A node that contains a list.

Properties
type String

The value is always "expression-list".

expr SQLNode

SQL expression for the list.

NullNode

Type Definition
NullNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, NullNode added at 4.24.

A node that contains NULL value.

Properties
type String

The value is always "null".

value null

Null value.

NumberNode

Type Definition
NumberNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, NumberNode added at 4.24.

A node that contains number.

Properties
type String

The value is always "number".

value Number

Numeric value.

SearchedCaseNode

Type Definition
SearchedCaseNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, SearchedCaseNode added at 4.24.

Node that contains case expression.

Properties
type String

The value is always "case-expression".

format String

Case expression format. Value for this property is always searched.

The value is always "searched".

clauses WhenNode[]

When clauses.

else SQLNode

Else SQL node.

SimpleCaseNode

Type Definition
SimpleCaseNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, SimpleCaseNode added at 4.24.

Simple case expression node. Case expressions provide a decoding capability that allows one expression to be transformed into another. Case expressions can appear anywhere that other forms of expressions can be used.

Properties
type String

The value is always "case_expression".

format String

The value is always "simple".

clauses WhenNode[]

When nodes.

operand SQLNode

SQL node.

else SQLNode

else sql node.

Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, SQLNode added at 4.24.

SQL parse tree is composed of SqlNodes. It may be an operator, literal, function, list, and so forth.

StringNode

Type Definition
StringNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, StringNode added at 4.24.

A node that contains string.

Properties
type String

The value is always "string".

value String

The string value.

TimeNode

Type Definition
TimeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, TimeNode added at 4.24.

A node that contains time.

Properties
type String

The value is always "date".

value String

The time value.

TimeStampNode

Type Definition
TimeStampNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, TimeStampNode added at 4.24.

A node that contains date.

Properties
type String

The value is always "timestamp".

value String

String date value.

UnaryNode

Type Definition
UnaryNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, UnaryNode added at 4.24.

A node that contains unary operator. Unary operators can be applied only to expressions that evaluate to any one of the data types of the numeric data type category.

Properties
type String

The value is always "unary-expression".

expr SQLNode

The sql node.

WhenNode

Type Definition
WhenNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24 WhereClause since 4.14, WhenNode added at 4.24.

Node that contains when clause.

Properties
type String

The value is always "when-clause".

operand SQLNode

operand.

value SQLNode

value.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.