diff --git a/usage/sync-rules/operators-and-functions.mdx b/usage/sync-rules/operators-and-functions.mdx index 789f69c6..f169c27e 100644 --- a/usage/sync-rules/operators-and-functions.mdx +++ b/usage/sync-rules/operators-and-functions.mdx @@ -17,36 +17,38 @@ Some fundamental restrictions on these operators and functions are: ### Operators -| Category | Operators | Notes | -| ------------------ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Comparison | \= != < \> \<= \>= | If either parameter is null, this evaluates to null. | -| Null | IS NULL, IS NOT NULL | | -| Mathematical | + \- \* / | | -| Logical | AND, OR, NOT | | -| Cast | CAST(x AS type) x :: type | Cast to text, numeric, integer, real or blob | -| JSON | json ->> 'path' json -> 'path' | \-> returns the value as a JSON string, while \->> returns the extracted value. The path can start with $., or just contain the key directly. | -| Text concatenation | \|| | Joins two text values together. | -| Arrays | \ IN \ | Returns true if the left value is present in the right JSON array.In data queries, only the left value may be a bucket parameter. In parameter queries, the left or right value may be a bucket parameter. Differs from the SQLite operator in that it can be used directly on a JSON array. | +| Category | Operators | Notes | +| ------------------ | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| Comparison | \= != < \> \<= \>= | If either parameter is null, this evaluates to null. | +| Null | IS NULL, IS NOT NULL | | +| Mathematical | + \- \* / | | +| Logical | AND, OR, NOT | | +| Cast | CAST(x AS type) x :: type | Cast to text, numeric, integer, real or blob | +| JSON | json \-\>\> 'path' json \-\> 'path' | \-\> returns the value as a JSON string, while \-\>\> returns the extracted value. | +| Text concatenation | | Joins two text values together. | +| Arrays | \ IN \ | Returns true if the left value is present in the right JSON array. In data queries, only the left value | ### Functions | Function | Description | | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| [upper(text)](https://www.sqlite.org/lang%5Fcorefunc.html#upper) | Convert text to upper case. | -| [lower(text)](https://www.sqlite.org/lang%5Fcorefunc.html#lower) | Convert text to lower case. | -| [hex(data)](https://www.sqlite.org/lang%5Fcorefunc.html#hex) | Convert blob or text data to hexadecimal text. | +| [upper(text)](https://www.sqlite.org/lang_corefunc.html#upper) | Convert text to upper case. | +| [lower(text)](https://www.sqlite.org/lang_corefunc.html#lower) | Convert text to lower case. | +| [substring(text, start, end)](https://sqlite.org/lang_corefunc.html#substr) | Extracts a portion of a string based on specified starting and ending indexes. | +| [hex(data)](https://www.sqlite.org/lang_corefunc.html#hex) | Convert blob or text data to hexadecimal text. | | base64(data) | Convert blob or text data to base64 text. | -| [length(data)](https://www.sqlite.org/lang%5Fcorefunc.html#length) | For text, return the number of characters. For blob, return the number of bytes. For null, return null. For integer and real, convert to text and return the number of characters. | -| [typeof(data)](https://www.sqlite.org/lang%5Fcorefunc.html#typeof) | text, integer, real, blob or null | +| [length(data)](https://www.sqlite.org/lang_corefunc.html#length) | For text, return the number of characters. For blob, return the number of bytes. For null, return null. For integer and real, convert to text and return the number of characters. | +| [typeof(data)](https://www.sqlite.org/lang_corefunc.html#typeof) | text, integer, real, blob or null | | [json\_extract(data, path)](https://www.sqlite.org/json1.html#jex) | Same as \->> operator, but the path must start with $. | -| [json\_array\_length(data)](https://www.sqlite.org/json1.html#jarraylen) | Given a JSON array (as text), returns the length of the array.if data is null, returns null. If the value is not a JSON array, returns 0. | +| [json\_array\_length(data)](https://www.sqlite.org/json1.html#jarraylen) | Given a JSON array (as text), returns the length of the array. If data is null, returns null. If the value is not a JSON array, returns 0. | | [json\_valid(data)](https://www.sqlite.org/json1.html#jvalid) | Returns 1 if the data can be parsed as JSON, 0 otherwise. | -| [ifnull(x,y)](https://www.sqlite.org/lang%5Fcorefunc.html#ifnull) | Returns x if non-null, otherwise returns y. | -| [unixepoch(datetime, \[modifier\])](https://www.sqlite.org/lang%5Fdatefunc.html) | Returns a datetime as Unix timestamp. If modifier is "subsec", the result is a floating point number, with milliseconds including in the fraction. The datetime argument is required - this function cannot be used to get the current time. | -| [datetime(datetime, \[modifier\])](https://www.sqlite.org/lang%5Fdatefunc.html) | Returns a datetime as a datetime string, in the format YYYY-MM-DD HH:MM:SS. If the specifier is "subsec", milliseconds are also included. If the modifier is "unixepoch", the argument is interpreted as a unix timestamp. Both modifiers can be included: datetime(timestamp, 'unixepoch', 'subsec'). The datetime argument is required - this function cannot be used to get the current time. | -| [ST\_AsGeoJSON(geometry)](https://postgis.net/docs/ST%5FAsGeoJSON.html) | Convert [PostGIS](https://postgis.net/) (in Postgres) geometry from WKB to GeoJSON. Combine with JSON operators to extract specific fields. | -| [ST\_AsText(geometry)](https://postgis.net/docs/ST%5FAsText.html) | Convert [PostGIS](https://postgis.net/) (in Postgres) geometry from WKB to Well-Known Text (WKT). | -| [ST\_X(point)](https://postgis.net/docs/ST%5FX.html) | Get the X coordinate of a [PostGIS](https://postgis.net/) point (in Postgres) | -| [ST\_Y(point)](https://postgis.net/docs/ST%5FY.html) | Get the Y coordinate of a [PostGIS](https://postgis.net/) point (in Postgres) | - -Most of these functions are based on the [built-in SQLite functions](https://www.sqlite.org/lang%5Fcorefunc.html) and [SQLite JSON functions](https://www.sqlite.org/json1.html). +| json\_keys(data) | Returns the set of keys as a JSON array. | +| [ifnull(x,y)](https://www.sqlite.org/lang_corefunc.html#ifnull) | Returns x if non-null, otherwise returns y. | +| [unixepoch(datetime, \[modifier\])](https://www.sqlite.org/lang_datefunc.html) | Returns a datetime as Unix timestamp. If modifier is "subsec", the result is a floating point number, with milliseconds including in the fraction. The datetime argument is required - this function cannot be used to get the current time. | +| [datetime(datetime, \[modifier\])](https://www.sqlite.org/lang_datefunc.html) | Returns a datetime as a datetime string, in the format YYYY-MM-DD HH:MM:SS. If the specifier is "subsec", milliseconds are also included. If the modifier is "unixepoch", the argument is interpreted as a unix timestamp. Both modifiers can be included: datetime(timestamp, 'unixepoch', 'subsec'). The datetime argument is required - this function cannot be used to get the current time. | +| [ST\_AsGeoJSON(geometry)](https://postgis.net/docs/ST_AsGeoJSON.html) | Convert [PostGIS](https://postgis.net/) (in Postgres) geometry from WKB to GeoJSON. Combine with JSON operators to extract specific fields. | +| [ST\_AsText(geometry)](https://postgis.net/docs/ST_AsText.html) | Convert [PostGIS](https://postgis.net/) (in Postgres) geometry from WKB to Well-Known Text (WKT). | +| [ST\_X(point)](https://postgis.net/docs/ST_X.html) | Get the X coordinate of a [PostGIS](https://postgis.net/) point (in Postgres) | +| [ST\_Y(point)](https://postgis.net/docs/ST_Y.html) | Get the Y coordinate of a [PostGIS](https://postgis.net/) point (in Postgres) | + +Most of these functions are based on the [built-in SQLite functions](https://www.sqlite.org/lang_corefunc.html) and [SQLite JSON functions](https://www.sqlite.org/json1.html).