sql

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

Creates a WhereClause expression that adheres to standardized SQL expressions. SQL expression is a combination of one or more values, operators and SQL functions that results in to a value.

Method Overview

Name Return Type Summary Object
Promise<WhereClause>

Parses the given where clause string and returns an instance of WhereClause when resolved.

sql

Method Details

parseWhereClause

Method
parseWhereClause(clause, fieldsIndex, timeZone){Promise<WhereClause>}

Parses the given where clause string and returns an instance of WhereClause when resolved. The WhereClause object can be used repeatedly against different features, to test if they individually meet the condition. The parser does not parse a whole SQL statement (ie. SELECT X… WHERE…). It only parses the expression after the where token.

Parameters
clause String

The SQL where clause expression.

fieldsIndex FieldsIndex

The fields index of the layer. The fields index is used to match the fields found in the where clause against the service, to fix casing for example.

timeZone String
optional
Default Value: "UTC"

The time zone in which SQL date functions are evaluated. The default is "UTC". This parameter only accepts IANA time zones.

Returns
Type Description
Promise<WhereClause> Parses a string where clause and returns a promise that resolves to an object with the WhereClause specification.
Examples
sql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex)
.then(function(clause){
  let testResult = clause.testFeature(
    new Graphic({
      attributes: {
        POPULATION: 300000
      }
    })
  );
  console.log(testResult); // prints true
});
sql.parseWhereClause(
  "START_TIME BETWEEN TIMESTAMP '2023-01-01 00:00:00' AND TIMESTAMP '2023-12-31 23:59:59'",
  layer.fieldsIndex
)
.then(function(clause){
  const utcDate = Date.UTC(2023, 0, 1, 0, 0, 0);
  let testResult = clause.testFeature(
    new Graphic({
      attributes: {
        START_TIME: utcDate
      }
    })
  );
  console.log(testResult); // true
});

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