Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The Cinchy system values covered in this section:
The @cinchy_row_id function returns the cinchy ID of the last-inserted row.
Similar to the SQL construct of table-valued functions, a Cinchy User Defined Function can be SELECTED or CROSS JOINED from -- as if it is a table.
The SELECT and FROM clause work the same for a table-valued UDF as they would for a regular Cinchy table.
To generate a table within a UDF for use in CQL, a dataTable will need to be created in the same format as the default Cinchy JSON Saved Query response (Image 1).
Cinchy Supported Functions covers the following topics:
Scalar Functions
Cinchy Functions and Cinchy User Defined Functions (UDFs) are used in conjunction with Cinchy and statements.
Cinchy System Values are specific to the Cinchy platform, similar to Cinchy Functions.
Cinchy User Defined Functions can be used for more customizable logic to accommodate your business requirements.
Scalar functions operate on a single value and return a single value.
The Cinchy functions covered in this section are:
The resolveLink function is used to insert or update values for link columns. It can be used either with values in the target table or by using the Cinchy Id.
Using resolveLink against non-unique data values may not return the same data response each time; in that scenario we recommend that you resolve using the CinchyID instead.
The currentUserID() function returns the currently logged in user's Cinchy Id. This is useful for setting up views as well as permissions.
You can use the below example in a view filter so that only the currently logged in user's tasks will appear.
The currentUsersGroups() function returns a list of the Cinchy Ids of groups that the current user belongs to, including any parent groups. For example, if a user is in the Cinchy Product
group and the Cinchy Product
group is under Cinchy Employees
, then both will be returned.
The executeSavedQuery function returns a scalar or list of scalar values from the saved query specified as the parameters of the function. There are two optional parameters for this function: CacheTimeout and RecordLimitForReturn.
Optional Parameter: Timeout
A cache expiry timeout for executeSavedQuery is an additional option that can be added. Simply add the number of seconds as a 3rd parameter to the function.
The RecordLimitForReturn parameter limits the amount of records returned. For example: If the query returns 10 records, but you set the parameter to 5, then you will get the first five records back.
The GetLastModifiedBy([Column]) function will return the CinchyID of the user who last modified the specified column. It is currently only supported in SELECT statements.
This example will return the CinchyID of the user who last modified the Name column in the Employees table.
This function allows you to query for draft values on tables where Change Approval is enabled.
When querying for draft data, the query result type needs to be set to "Query Results (including Draft Data)"
Example
In this example, we want to query all data in the Employees table, including the data that is pending a change request (Image 1).
To return results that include the draft changes in the First Name column, we would set our query results to Include Draft Data, and use the following syntax (Image 2):
These functions support data type casting and conversion. Conversion functions convert an expression of one data type to another data type. The conversion functions covered in this section are:
This function is used with CONVERT to convert an expression of one data type to another.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations.
expression
Any valid expression
data_type
The target data type.
length
An optional integer that specifies the length of the target data type, for data types that allow a user specified length.
Returns expression
, translated to data_type
This function is used with CAST to convert an expression of one data type to another.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
expression
Any valid expression
data_type
The target data type.
length
An optional integer that specifies the length of the target data type, for data types that allow a user specified length.
style
An optional integer expression that specifies how the CONVERT function will translate expression. For a style value of NULL, NULL is returned. data_type determines the range.
Similar to the SQL construct of scalar-valued functions. A Scalar-valued function in Cinchy is used to return a single value of any CQL data type. The function body can execute any JavaScript logic.
Select a scalar value UDF as a column (Image 1).
Scalar-valued functions have to be invoked with a parameter, even if the definition of the function does not require a parameter. You can pass a string:
SELECT my_scalar('a') FROM [Cinchy].[Tables] WHERE [Deleted] IS NULL AND [Cinchy Id]=1
Once it is confirmed that the UDF returns the expected result though a query, a calculated column can be include.
Depending on how intensive or live you want the calculation to be, choose whether to make it a live or cached calculated column.
Simply add your UDF to the calculated column (Image 2).
To use the UDF to trigger an action (ex. create a row in another table), it should be a cached calculated column. Here are a few scenarios to watch out for:
Do not trigger when you do not have all the necessary fields
Do not trigger when non-relevant data on the row changes
Make sure to appropriately insert and/or update in another table
User Defined Functions provide customers with a way to specify and use more particular logic in your solutions than plain CQL may allow. It can be used to simplify calculations and orchestrate automations to accommodate your business requirements.
UDFs are written in Javascript.
There are two (2) groups of Cinchy User Defined Functions (UDF's):
User Defined Functions (UDFs) are registered in the Cinchy User Defined Functions table (Image 1).
A user defined function in Cinchy is written in Javascript, and comes in the form of:
It can perform external API calls and execute Cinchy Queries. Generally, at least something should be returned as an indication of success or failure even if you do not want to return any values.
Helper functions can be created within a UDF, however you cannot reference other UDFs in your UDF.
To use advanced functions in UDFs, import the following.
The following functions can be used in a Cinchy User Defined Function (but not in CQL directly).
An XMLHttpRequest() helper can be used to help POST or GET data from an external API. Note that Cinchy basicAuthAPIs can also be accessed this way.
A Cinchy query or a non query (not expecting a result back) can be executed in a UDF as well.
You can review the full list of in-progress function translations.
- Similar to the SQL construct of table-valued functions, a Cinchy User Defined Function can be SELECTED or CROSS JOINED from as if it is a table.
- Similar to the SQL construct of scalar-valued functions. A Scalar-valued function in Cinchy is used to return a single value of any CQL data type. The function body can execute any JavaScript logic.
Cinchy UDFs run , which uses ECMAScript 5.1.
If you are having issues with your script, we suggest pasting it into , a tool that helps to detect errors and potential problems in your JavaScript code, as it also runs ECMAScript 5.1.
Method | Description |
---|
Method | Description |
---|
Value | Definiton |
Function Name | GetLastModifiedBy |
Function Description | This function function will return the CinchyID of the user who last modified the specified column. |
Function Type | Scalar |
Return Type | Numeric. It returns the CinchyID |
Without century | With century | Input/Output | Standard |
0 | 100 | mon dd yyyy hh:miAM/PM | Default |
1 | 101 | mm/dd/yyyy | US |
2 | 102 | yyyy.mm.dd | ANSI |
3 | 103 | dd/mm/yyyy | British/French |
4 | 104 | dd.mm.yyyy | German |
5 | 105 | dd-mm-yyyy | Italian |
6 | 106 | dd mon yyyy | - |
7 | 107 | Mon dd, yyyy | - |
8 | 108 | hh:mm:ss | - |
9 | 109 | mon dd yyyy hh:mi:ss:mmmAM (or PM) | Default + millisec |
10 | 110 | mm-dd-yyyy | USA |
11 | 111 | yyyy/mm/dd | Japan |
12 | 112 | yyyymmdd | ISO |
13 | 113 | dd mon yyyy hh:mi:ss:mmm | Europe (24 hour clock) |
14 | 114 | hh:mi:ss:mmm | 24 hour clock |
20 | 120 | yyyy-mm-dd hh:mi:ss | ODBC canonical (24 hour clock) |
21 | 121 | yyyy-mm-dd hh:mi:ss.mmm | ODBC canonical (24 hour clock) |
- | 126 | yyyy-mm-ddThh:mi:ss.mmm | ISO8601 |
- | 127 | yyyy-mm-ddThh:mi:ss.mmmZ | ISO8061 (with time zone Z) |
- | 130 | dd mon yyyy hh:mi:ss:mmmAM | Hijiri |
- | 131 | dd/mm/yy hh:mi:ss:mmmAM | Hijiri |
Value | Explanation |
0 | Maximum 6 digits (default) |
1 | 8 digits |
2 | 16 digits |
Value | Explanation |
0 | No comma delimiters, 2 digits to the right of decimal |
1 | Comma delimiters, 2 digits to the right of decimal |
2 | No comma delimiters, 4 digits to the right of decimal |
Column Name | Description |
Name | The Name column contains the name of the User Defined Function. WARNING: Do not name UDFs the same names as SQL or CQL functions (for example, do not name your UDF "CONCAT"). Doing so may cause your platform to break. |
Script | The Script column can contain any number of JavaScript functions that are necessary and referenced by the single function that is registered in the Name column |
Open | This creates the HttpClient() |
setRequestHeader | This adds the header to the client |
Send | This uses the client to call Get() |
Send (postdata) | This uses the client to call POST, PUT, etc. |
Status | This is attributed to show the status of a client response |
responseText | This is attributed to show the response text after the client is called |
executeNonQuery | This is used for INSERTS, DELETES, and UPDATES. It returns a Long value. |
executeQuery | This is used for SELECT statement. It returns system.data values. |
executeBatchUpsert | This performs a batch upsert into Cinchy. It returns int values. |
Data type | Format | Range | Accuracy | Storage size (bytes) | User-defined fractional second precision | Time zone offset |
time | hh:mm:ss[.nnnnnnn] | 00:00:00.0000000 through 23:59:59.9999999 | 100 nanoseconds | 3 to 5 | Yes | No |
date | YYYY-MM-DD | 0001-01-01 through 9999-12-31 | 1 day | 3 | No | No |
smalldatetime | YYYY-MM-DD hh:mm:ss | 1900-01-01 through 2079-06-06 | 1 minute | 4 | No | No |
datetime | YYYY-MM-DD hh:mm:ss[.nnn] | 1753-01-01 through 9999-12-31 | 0.00333 second | 8 | No | No |
datetime2 | YYYY-MM-DD hh:mm:ss[.nnnnnnn] | 0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 | 100 nanoseconds | 6 to 8 | Yes | No |
datetimeoffset | YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm | 0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 (in UTC) | 100 nanoseconds | 8 to 10 | Yes | |
The validate date and time value function covered in this section is:
ISDATE checks an expression to see if it is correct.
It will return 1 if the expression is a valid date, time, or datetime value; otherwise, it will return 0. ISDATE will also return 0 if the expression is a datetime2 value.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
expression
Is a character string or expression that can be converted to a character string. The expression must be less than 4,000 characters. Date and time data types, except datetime and smalldatetime, are not allowed as the argument for ISDATE.
ISDATE is deterministic only when used with the CONVERT function, if the CONVERT style parameter is specified, and style is not equal to 0, 100, 9, or 109.
The return value of ISDATE depends on the settings set by SET DATEFORMAT, SET LANGUAGE and Configure the default language Server Configuration Option.
Using ISDATE to Test Valid datetime Expression
The following return date and time values from their parts functions covered in this section are:
This function returns a date value that maps to the specified year, month, and day values.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
year
An integer expression that specifies a year.
month
An integer expression that specifies a month, from 1 to 12.
day
An integer expression that specifies a day.
DATEFROMPARTS
returns a date value, with the date portion set to the specified year, month and day, and the time portion set to the default. For invalid arguments, DATEFROMPARTS
will raise an error. DATEFROMPARTS
returns null if at least one required argument has a null value.
DATETIME2FROMPARTS function returns a datetime2 value for the specified date and time arguments. The returned value has a precision specified by the precision argument.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
year
An integer expression that specifies a year.
month
An integer expression that specifies a month.
day
An integer expression that specifies a day.
hour
An integer expression that specifies the hours.
minute
An integer expression that specifies the minutes.
seconds
An integer expression that specifies the seconds.
fractions
An integer expression that specifies a fractional seconds value.
percision
An integer expression that specifies the precision of the datetime2 value that DATETIME2FROMPARTS
will return.
DATETIME2FROMPARTS
returns a fully initialized datetime2 value. DATETIME2FROMPARTS
will raise an error if at least one required argument has an invalid value. DATETIME2FROMPARTS
returns null if at least one required argument has a null value. However, if the precision argument has a null value, DATETIME2FROMPARTS
will raise an error.
The fractions argument depends on the precision argument. For example, for a precision value of 7, each fraction represents 100 nanoseconds; for a precision of 3, each fraction represents a millisecond. For a precision value of zero, the value of fractions must also be zero; otherwise, DATETIME2FROMPARTS
will raise an error.
Example 1: Without Fractions of a Second
Example 2: With Fractions of a Second
When fractions have a value of 5, and precision has a value of 1, the value of fractions represents 5/10 of a second.
When fractions have a value of 50, and precision has a value of 2, the value of fractions represents 50/100 of a second.
When fractions have a value of 500, and precision has a value of 3, then the value of fractions represents 500/1000 of a second.
DATETIMEFROMPARTS function returns a datetime value for the specified date and time arguments.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
year
An integer expression that specifies a year.
month
An integer expression that specifies a month.
day
An integer expression that specifies a day.
hour
An integer expression that specifies hours.
minute
An integer expression that specifies minutes.
seconds
An integer expression that specifies seconds.
milliseconds
An integer expression that specifies milliseconds.
DATETIMEFROMPARTS
returns a fully initialized datetime value. DATETIMEFROMPARTS
will raise an error if at least one required argument has an invalid value. DATETIMEFROMPARTS
returns null if at least one required argument has a null value.
Returns a datetimeoffset value for the specified date and time arguments. The returned value has a precision specified by the precision argument and an offset as specified by the offset arguments.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
year
An integer expression that specifies a year.
month
An integer expression that specifies a month.
day
An integer expression that specifies a day.
hour
An integer expression that specifies hours.
minute
An integer expression that specifies minutes.
seconds
An integer expression that specifies seconds.
frcations
An integer expression that specifies a fractional seconds value.
hour_offset
An integer expression that specifies the hour portion of the time zone offset.
minute_offset
An integer expression that specifies the minute portion of the time zone offset.
precision
An integer literal value that specifies the precision of the datetimeoffset value that DATETIMEOFFSETFROMPARTS
will return.
DATETIMEOFFSETFROMPARTS
returns a fully initialized datetimeoffset data type. The offset arguments represent the time zone offset. For omitted offset arguments, DATETIMEOFFSETFROMPARTS
assumes a time zone offset of 00:00
- in other words, no time zone offset. For specified offset arguments, DATETIMEOFFSETFROMPARTS
expects values for both arguments, and both values positive or negative. If minute_offset has a value and hour_offset has no value, DATETIMEOFFSETFROMPARTS
will raise an error. DATETIMEOFFSETFROMPARTS
will raise an error if the other arguments have invalid values. If at least one required arguments have a NULL
value, then DATETIMEOFFSETFROMPARTS
will return NULL
. However, if the precision argument has a NULL
value, then DATETIMEOFFSETFROMPARTS
will raise an error.
The fractions argument depends on the precision argument. For example, for a precision value of 7, each fraction represents 100 nanoseconds; for a precision of 3, each fraction represents a millisecond. For a precision value of zero, the value of fractions must also be zero; otherwise, DATETIMEOFFSETFROMPARTS
will raise an error.
Example 1: Without Fractions of a Second
Example 2: With Fractions of a Second
This example shows the use of the fractions and precision parameters:
When fractions have a value of 5, and precision has a value of 1, the value of fractions represents 5/10 of a second.
When fractions have a value of 50, and precision has a value of 2, the value of fractions represents 50/100 of a second.
When fractions have a value of 500, and precision has a value of 3, then the value of fractions represents 500/1000 of a second.
SMALLDATETIMEFROMPARTS returns a smalldatetime value for the specified date and time.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
year
Integer expression specifying a year.
month
Integer expression specifying a month.
day
Integer expression specifying a day.
hour
Integer expression specifying hours.
minute
Integer expression specifying minutes.
This function acts as a constructor for a fully initialized smalldatetime value. If the arguments are not valid, then an error is thrown. If required arguments are null, then null is returned.
TIMEFROMPARTS returns a time value for the specified time and with the specified precision.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
hour
Integer expression specifying hours.
minute
Integer expression specifying minutes.
seconds
Integer expression specifying seconds.
fractions
Integer expression specifying fractions.
precision
Integer literal specifying the precision of the time value to be returned.
TIMEROMPARTS returns a fully initialized time value. If the arguments are invalid, then an error is raised. If any of the parameters are null, null is returned. However, if the precision argument is null, then an error is raised.
The fractions argument depends on the precision argument. For example, if precision is 7, then each fraction represents 100 nanoseconds; if precision is 3, then each fraction represents a millisecond. If the value of precision is zero, then the value of fractions must also be zero; otherwise, an error is raised.
Example 1: Without Fractions of a Second
Example 2: With Fractions of a Second
The following example demonstrates the use of the fractions and precision parameters:
When fractions have a value of 5 and precision has a value of 1, then the value of fractions represents 5/10 of a second.
When fractions have a value of 50 and precision has a value of 2, then the value of fractions represents 50/100 of a second.
When fractions have a value of 500 and precision has a value of 3, then the value of fractions represents 500/1000 of a second.
SQL derives all system date and time values from the operating system of the computer on which the instance of SQL Server runs.
SQL Server 2019 (15.x) derives the date and time values through use of the GetSystemTimeAsFileTime() Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of SQL Server running. This API has a precision fixed at 100 nanoseconds. Use the GetSystemTimeAdjustment() Windows API to determine the accuracy.The return system date and time value functions covered in this section are:
SYSDATETIME returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
SQL statements can refer to SYSDATETIME anywhere they can refer to a datetime2(7) expression.
SYSDATETIME is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.
Example 1: Getting the Current System Date and Time
Example 2: Getting the Current System Date
Example 3: Getting the Current System Time
SYSDATETIMEOFFSET returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
SQL statements can refer to SYSDATETIMEOFFSET anywhere they can refer to a datetimeoffset expression.
SYSDATETIMEOFFSET is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.
Example 1: Showing Formats Returned by the Date and Time Functions
Example 2: Converting Date and Time to Date
Example 3: Converting Date and Time to Times
SYSUTCDATETIME returns a datetime2 value that contains the date and time of the computer on which the instance of SQL Server is running. The date and time are returned as UTC time (Coordinated Universal Time). The fractional second precision specification has a range from 1 to 7 digits. The default precision is 7 digits.
SQL statements can refer to SYSUTCDATETIME anywhere they can refer to a datetime2 expression.
SYSUTCDATETIME is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.
Example 1: Showing Formats Returned by Date and Time functions
Example 2: Converting Date and Time to Date
Example 3: Converting Date and Time to Time
The logical functions covered in this section are:
The CHOOSE function returns an item at the specified index from a list of values in Cinchy.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
index
Is an integer expression that represents a 1-based index into the list of the items following it.
If the provided index value has a numeric data type other than int, then the value is implicitly converted to an integer. If the index value exceeds the bounds of the array of values, then CHOOSE returns null.
Returns the data type with the highest precedence from the set of types passed to the function.
CHOOSE acts like an index into an array, where the array is composed of the arguments that follow the index argument. The index argument determines which of the following values will be returned.
Simple CHOOSE example
Simple CHOOSE example based on column
CHOOSE in combination with MONTH
The following example returns the season in which a user was added to Cinchy. The MONTH function is used to return the month value from the column HireDate
.
IFF returns one of two values which is depending on if the Boolean expression evaluates TRUE or FALSE in the Cinchy.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
boolean_expression
A valid Boolean expression.
If this argument is not a Boolean expression, then a syntax error is raised.
true_value
Value to return if boolean_expression evaluates to true.
false_value
Value to return if boolean_expression evaluates to false.
Returns the data type with the highest precedence from the types in true_value
and false_value
.
IIF is a second version of writing a CASE expression. It evaluates the Boolean expression which was passed as the first argument and then returns either TRUE or FALSE based on the result of the evaluation. Thetrue_value
is returned if the Boolean expression is TRUE, and thefalse_value
is returned if the Boolean expression is FALSE or unknown.
Return 5 if the condition is TRUE, or 10 if the condition is FALSE:
With Cinchy, you can now easily create spatial tables with geometry and geography data sets, and blend this with other sources to unlock more intelligence from your fabric.
This data can be leveraged to support an endless number of use-cases that rely on location and mapping data to help your teams make the most informed decisions.
The geometry and geography functions covered in this section are categorized as follows:
The return date and time difference value functions covered in this section are:
DATDIFF function returns the count of the specified datepart boundaries crossed between the specified startdate and enddate.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
datepart
The units in which DATEDIFF reports the difference between the startdate and enddate. Commonly used datepart units include month
or second
.
The datepart value cannot be specified in a variable, nor as a quoted string like 'month'
.
The following table lists all the valid datepart values. DATEDIFF accepts either the full name of the datepart, or any listed abbreviation of the full name.
startdate
An expression that can resolve to one of the following values:
date
datetime
datetimeoffset
smalldatetime
time
Use four-digit years to avoid ambiguity.
Use DATEDIFF
in the SELECT <list>
, WHERE
, HAVING
, GROUP BY
and ORDER BY
clauses.
DATEDIFF
implicitly casts string literals as a datetime2 type. This means that DATEDIFF
does not support the format YDM when the date is passed as a string. You must explicitly cast the string to a datetime or smalldatetime type to use the YDM format.
Specifying SET DATEFIRST
has no effect on DATEDIFF
. DATEDIFF
always uses Sunday as the first day of the week to ensure the function operates in a deterministic way.
DATEDIFF
may overflow with a precision of minute or higher if the difference between enddate and startdate returns a value that is out of range for int.
Finding the number of days between two dates.
Specifying user-defined variables for startdate and enddate
Example 3: Specifying scalar system functions for startdate and enddate
DATEIFF_BIG function returns the count of the specified datepart boundaries crossed between the specified startdate and enddate.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
datepart
The part of startdate and enddate that specifies the type of boundary crossed.
This table lists all valid datepart argument names and abbreviations.
startdate
An expression that can resolve to one of the following values:
date
datetime
datetimeoffset
smalldatetime
time
For date, DATEDIFF_BIG
will accept a column expression, expression, string literal, or user-defined variable. A string literal value must resolve to a datetime. Use four-digit years to avoid ambiguity issues. DATEDIFF_BIG
subtracts startdate from enddate. To avoid ambiguity, use four-digit years.
Use DATEDIFF_BIG
in the SELECT <list>
, WHERE
, HAVING
, GROUP BY
and ORDER BY
clauses.
DATEDIFF_BIG
implicitly casts string literals as a datetime2 type. This means that DATEDIFF_BIG
does not support the format YDM when the date is passed as a string. You must explicitly cast the string to a datetime or smalldatetime type to use the YDM format.
Specifying SET DATEFIRST
has no effect on DATEDIFF_BIG
. DATEDIFF_BIG
always uses Sunday as the first day of the week to ensure the function operates in a deterministic way.
DATEDIFF_BIG
may overflow with a precision of nanosecond if the difference between enddate and startdate returns a value that is out of range for bigint.
This example uses different types of expressions as arguments for the startdate and enddate parameters. It calculates the number of day boundaries crossed between dates in two columns of a table.
The modify date and time value functions covered in this section are:
DATEADD function adds a specified number value to a specified datepart of an input date value, and then returns that modified value.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
datepart
The part of date to which DATEADD
adds an integer number. This table lists all valid datepart arguments.
number
An expression that can resolve to an int that DATEADD
adds to a datepart of date. DATEADD
accepts user-defined variable values for number. DATEADD
will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.
date
An expression that can resolve to one of the following values:
date
datetime
datetimeoffset
datetime2
smalldatetime
time
For date, DATEADD
will accept a column expression, expression, string literal, or user-defined variable. A string literal value must resolve to a datetime. Use four-digit years to avoid ambiguity issues.
The return value data type for this method is dynamic. The return type depends on the argument supplied for date
. If the value for date
is a string literal date, DATEADD
returns a datetime value. If another valid input data type is supplied for date
, DATEADD
returns the same data type. DATEADD
raises an error if the string literal seconds scale exceeds three decimal place positions (.nnn) or if the string literal contains the time zone offset part.
Incrementing datepart by an interval of 1
Incrementing more than one level of datepart in one statement
Each of these statements increments datepart by a number large enough to additionally increment the next higher datepart of date:
Using expressions as arguments for the number and date parameters
Specifying a column as date
This example adds 2
(two) days to each value in the OrderDate
column, to derive a new column named PromisedShipDate
:
The EOMONTH function returns the last day of the month containing a specified date, with an optional offset.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
start_date
A date expression that specifies the date for which to return the last day of the month.
month_to_add
An optional integer expression that specifies the number of months to add to start_date.
If the month_to_add argument has a value, then EOMONTH
adds the specified number of months to start_date, and then returns the last day of the month for the resulting date. If this addition overflows the valid range of dates, then EOMONTH
will raise an error.
The EOMONTH
function can remote to SQL Server 2012 (11.x) servers and higher. It cannot be remote to servers with a version lower than SQL Server 2012 (11.x).
EOMONTH with explicit datetime type
EOMONTH with string parameter and implicit conversion
EOMONTH with and without the month_to_add parameter
The SWITCHOFFSEET function returns a datetimeoffset value that is changed from the stored time zone offset to a specified new time zone offset.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
DATETIMEOFFSET
DATETIMEOFFSET
Is an expression that can be resolved to a datetimeoffset(n) value.
time_zone
Is a character string in the format [+|-]TZH:TZM or a signed integer (of minutes) that represents the time zone offset, and is assumed to be daylight-saving aware and adjusted.
datetimeoffset with the fractional precision of the DATETIMEOFFSET argument.
Use SWITCHOFFSET to select a datetimeoffset value into a time zone offset that is different from the time zone offset that was originally stored. SWITCHOFFSET does not update the stored time_zone value.
SWITCHOFFSET can be used to update a datetimeoffset column.
Using SWITCHOFFSET with the function GETDATE() can cause the query to run slowly. This is because the query optimizer is unable to obtain accurate cardinality estimates for the datetime value. To resolve this problem, use the OPTION (RECOMPILE) query hint to force the query optimizer to recompile a query plan the next time the same query is executed. The optimizer will then have accurate cardinality estimates and will produce a more efficient query plan.
TODATETIMEOFFSET function returns a datetimeoffset value that is translated from a datetime2 expression.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
expression
Is an expression that resolves to a datetime2 value.
time_zone
Is an expression that represents the time zone offset in minutes (if an integer), for example -120, or hours and minutes (if a string), for example '+13:00'. The range is +14 to -14 (in hours). The expression is interpreted in local time for the specified time_zone.
datetimeoffset. The fractional precision is the same as the datetime argument.
Changing the time zone offset of the current date and time
The following example changes the zone offset of the current date and time to time zone -07:00
.
Changing the time zone offset in minutes
The following example changes the current time zone to -120
minutes.
Adding a 13-hour time zone offset
The following example adds a 13-hour time zone offset to a date and time.
The return date and time part functions covered in this section are:
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
The DATENAME function returns a character string representing the specified datepart of the specified date.
datepart
The specific part of the date argument that DATENAME
will return. This table lists all valid datepart arguments.
date
An expression that can resolve to one of the following data types:
date
datetime
datetimeoffset
datetime2
smalldatetime
time
For date, DATENAME
will accept a column expression, expression, string literal, or user-defined variable. Use four-digit years to avoid ambiguity issues.
Use DATENAME
in the following clauses:
GROUP BY
HAVING
ORDER BY
SELECT <list>
WHERE
SELECT DATENAME(datepart,'2007-10-30 12:15:32.1234567 +05:10');
Result Set
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
DATEPART function returns an integer representing the specified datepart of the specified date.
datepart
The specific part of the date argument for which DATEPART
will return an integer. This table lists all valid datepart arguments.
date
An expression that resolves to one of the following data types:
date
datetime
datetimeoffset
datetime2
smalldatetime
time
For date, DATEPART
will accept a column expression, expression, string literal, or user-defined variable. Use four-digit years to avoid ambiguity issues.
DATEPART
can be used in the select list, WHERE, HAVING, GROUP BY, and ORDER BY clauses.
DATEPART implicitly casts string literals as a datetime2 type in SQL Server 2019 (15.x). This means that DATENAME does not support the format YDM when the date is passed as a string. You must explicitly cast the string to a datetime or smalldatetime type to use the YDM format.
Example 1: Returns Base Year
Example 2: Returns Day the Day Part of the Date
Example 3: Returns the year Part of the Date
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
DAY function returns an integer that represents the day (day of the month) of the specified date.
date
An expression that resolves to one of the following data types:
date
datetime
datetimeoffset
datetime2
smalldatetime
time
For date, DAY
will accept a column expression, expression, string literal, or user-defined variable.
Example 1:
This returns 30
- the number of the day itself
Example 2:
This statement returns 1900, 1, 1
. The date argument has a number value of 0
. SQL Server interprets 0
as January 1, 1900.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
MONTH returns an integer that represents the month of the specified date.
date
Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value. The date argument can be an expression, column expression, user-defined variable, or string literal.
Example 1:
The following statement returns 4
. This is the number of the month.
Example 2:
The following statement returns 1900, 1, 1
. The argument for date is the number 0
. SQL Server interprets 0
as January 1, 1900.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
YEAR function returns an integer that represents the year of the specified date.
date
Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value. The date argument can be an expression, column expression, user-defined variable or string literal.
Example 1:
The following statement returns 2020
. This is the number of the year.
Example 2:
The following statement returns 1900, 1, 1
. The argument for date is the number 0
. SQL Server interprets 0
as January 1, 1900.
Cinchy CQL supports a number of extended methods on Open Geospatial Consortium (OGC) methods on geometry and geography instances.Please note that all functions that have been denoted with Geography in parentheses are only applicable to OGC methods on geometry instances.
These function are not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations here.
The extended Methods covered in this section are:
IsValidDetailed()
returns a message that can help to identify problems with a spatial object that is not valid.
Only the first error is returned, when the object is not valid. When the object is valid, a value of 24400 is returned.
CQL: Text
The following table contains possible return values:
This example of an invalid spatial object shows how the IsValidDetailed()
methods behaves:
MakeValid()
converts an invalid geometry instance into a geometry instance with a valid Open Geospatial Consortium (OGC) type.
CQL: geometry
This method may cause a change in the type of the geometry instance, as well as cause the points of a geometry instance to shift slightly.
This example creates an invalid LineString
instance that overlaps itself and uses MakeValid()
to make this instance valid:
By running the Douglas-Peucker algorithm on the instance with the given tolerance, Reduce()
returns an approximation of the given geometry instance produced.
tolerance The tolerance (type float) to input for the approximation algorithm.
CQL: geometry
This algorithm operates independently on each geometry contained in the instance, for collection types.
Does not modify Point
instances.
For CircularString
instances,Reduce()
returns a LineString
, CircularString
, or CompoundCurve
instance.
For CompoundCurve
instances,Reduce()
returns either a CompoundCurve
or LineString
instance.
On Polygon
instances, the approximation algorithm is applied independently to each ring. If the returned Polygon
instance is not valid, Reduce()
will produce a FormatException.
When a circular arc segment is found, the approximation algorithm checks whether the arc can be approximated by its chord within half the given tolerance. Chords meeting this criteria have the circular arc replaced in the calculations by the chord. If a chord doesn't meet this criteria, then the circular arc is kept and the approximation algorithm is applied to the remaining segments.
This example creates a LineString
instance and uses Reduce()
to simplify the instance:
ShortestLineTo()
returns a LineString
instance (which is the distance between the two geometry instances) with two points that represent the shortest distance between the two geometry instances.
other_instance Specifies the second geometry instance that the calling geometry instance is trying to determine the shortest distance to.
CQL: geometry
Returns a LineString
instance with endpoints lying on the borders of the two non-intersecting geometry instances being compared.
The length of the LineString
returned equals the shortest distance between the two geometry instances.
An empty LineString
instance is returned when the two geometry instances intersect each other.
This example returns the LineString
instance connecting the two points, by finding the shortest distance between a CircularString
instance and a LineString
instance:
Mathematical functions perform calculations based on input values provided as parameters to the functions, and return numeric values.
The mathematical functions covered in this section are:
A mathematical function that returns the absolute (positive) value of the specified numeric expression. (ABS
changes negative values to positive values. ABS
has no effect on zero or positive values.)
numeric_expression
An expression of the exact numeric or approximate numeric data type category.
Returns the same type as numeric_expression.
This example shows the results of using the ABS
function on three different numbers.
A function that returns the angle, in radians, whose cosine is the specified float expression. This is also called arccosine.
float_expression
An expression of either type float or of a type that can implicitly convert to float. Only a value ranging from -1.00 to 1.00 is valid. Values outside this range return NULL and ACOS will report a domain error.
float
This example returns the ACOS
value of the specified angle.
A function that returns the angle, in radians, whose sine is the specified float expression. This is also called arcsine.
float_expression
An expression of either type float or of a type that can implicitly convert to float. Only a value ranging from -1.00 to 1.00 is valid. Values outside this range return NULL and ASIN will report a domain error.
float
This example returns the ASIN
value of the specified angle.
A function that returns the angle, in radians, whose tangent is a specified float expression. This is also called arctangent.
float_expression
An expression of either type float or of a type that implicitly converts to float.
float
This example returns the ATAN
value of the specified angle.
Returns the angle, in radians, between the positive x-axis and the ray from the origin to the point (y, x), where x and y are the values of the two specified float expressions.
float_expression
An expression of data type float.
float
The following example calculates the ATN2
for the specified x
and y
components.
This function returns the smallest integer greater than, or equal to, the specified numeric expression.
numeric_expression
An expression of the exact numeric or approximate numeric data type category. For this function, the bit data type is invalid
Return values have the same type as numeric_expression.
This example shows positive numeric, negative numeric, and zero value inputs for the CEILING function.
A mathematical function that returns the trigonometric cosine of the specified angle - measured in radians - in the specified expression.
float_expression
An expression of type float.
float
This example returns the COS
value of the specified angle.
A mathematical function that returns the trigonometric cotangent of the specified angle - in radians - in the specified float expression.
float_expression
An expression of type float, or of a type that can implicitly convert to float.
float
This example returns the COT
value for the specific angle.
This function returns the corresponding angle, in degrees, for an angle specified in radians.
numeric_expression
An expression of the exact numeric or approximate numeric data type category, except for the bit data type.
Returns a value whose data type matches the data type of numeric_expression.
This example returns the number of degrees in a specified radian.
Returns the exponential value of the specified float expression.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
float
The following example uses a compounding interest example to illustrate the use of EXP.
Returns the largest integer less than or equal to the specified numeric expression.
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
Returns the same type as numeric_expression.
The following example shows positive numeric, negative numeric, and zero value inputs with the FLOOR
function.
Returns the natural logarithm of the specified float expression in SQL Server.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
base
Optional integer argument that sets the base for the logarithm.
Applies to: SQL Server 2012 (11.x) and later
float
By default, LOG() returns the natural logarithm. Starting with SQL Server 2012 (11.x), you can change the base of the logarithm to another value by using the optional base parameter.
The natural logarithm is the logarithm to the base e, where e is an irrational constant approximately equal to 2.718281828.
The natural logarithm of the exponential of a number is the number itself: LOG( EXP( n ) ) = n. And the exponential of the natural logarithm of a number is the number itself: EXP( LOG( n ) ) = n.
The following example calculates the LOG
for a specified number.
Returns the base-10 logarithm of the specified float expression.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
float
The LOG10 and POWER functions are inversely related to one another. For example, 10 ^ LOG10(n) = n.
Calculating the base 10 logarithm for a variable.
The following example calculates the LOG10
of the specified number.
Calculating the result of raising a base-10 logarithm to a specified power.
The following example returns the result of raising a base-10 logarithm to a specified power.
Returns the constant value of PI.
float
The following example returns the value of PI
.
Returns the value of the specified expression to the specified power.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
y
Is the power to which to raise float_expression. y can be an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
The return type depends on the input type of float_expression:
If the result does not fit in the return type, an arithmetic overflow error occurs.
The following example demonstrates raising a specified number to a specified power.
Returns radians when a numeric expression, in degrees, is entered.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
Returns the same type as numeric_expression.
The following example shows the number of radians based on a specified degree.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
Returns a pseudo-random float value from 0 through 1, exclusive.
seed
Is an integer expression (tinyint, smallint, or int) that gives the seed value. If seed is not specified, the SQL Server Database Engine assigns a seed value at random. For a specified seed value, the result returned is always the same.
float
Repetitive calls of RAND() with the same seed value return the same results.
For one connection, if RAND() is called with a specified seed value, all subsequent calls of RAND() produce results based on the seeded RAND() call. For example, the following query will always return the same sequence of numbers.
Returns a numeric value, rounded to the specified length or precision.
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
length
Is the precision to which numeric_expression is to be rounded. length must be an expression of type tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.
function
Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.
Returns the following data types.
ROUND always returns a value. If length is negative and larger than the number of digits before the decimal point, ROUND returns 0.
ROUND returns a rounded numeric_expression, regardless of data type, when length is a negative number.
Using ROUND and estimates
The following example shows two expressions that demonstrate by using ROUND
the last digit is always an estimate.
Using ROUND and rounding approximations
The following example shows rounding and approximations.
Using ROUND to truncate
The following example uses two SELECT
statements to demonstrate the difference between rounding and truncation. The first statement rounds the result. The second statement truncates the result.
Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
The following example returns the SIGN values of a positive number, negative number, and zero.
Returns the trigonometric sine of the specified angle, in radians, and in an approximate numeric, float, expression.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float, in radians.
float
The following example calculates the SIN for a specified angle.
Returns the square root of the specified float value.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
float
The following example returns the square root of a number.
Returns the square of the specified float value.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
float
The following example returns the square of a specified number.
Returns the tangent of the input expression.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float, interpreted as a number of radians.
float
The following example returns the tangent of a specified angle.
The set of functions listed in this page are for use in when configuring data syncs.
This function is used in Connections to escape parameter values and be safe to use inside a JSON document without breaking it
This function can be used in a REST API connection anywhere that allows parameters to be, such as the URL endpoint, the Request Body, or a Post-Sync Script.
Argument | Description |
---|
The following example shows how you would use JSON_ESCAPE in your REST API URL (Image 1).
In this example we have an API and want to add a value (@Parameter) that contains double quotes -- this could break the JSON structure, so we need to wrap the parameter with JSON_ESCAPE().
The following example shows how you would use JSON_ESCAPE in your REST API Request Body (Image 2).
In this example we have an API and want to add a value (@Parameter) that contains double quotes -- this could break the JSON structure, so we need to wrap the parameter with JSON_ESCAPE().
This function is used in Connections to escape parameter values and be safe to use inside a URL without breaking it
This function can be used in a REST API connection anywhere that allows parameters to be, such as the URL endpoint, the Request Body, or a Post-Sync Script.
The following example shows how you would use URL_ESCAPE in your REST API URL (Image 3).
In this example we have an API and want to add a value (@Parameter) that contains the "&" symbol to the URL field. To properly read the URL, we need to wrap the parameter with URL_ESCAPE(), which will escape the & to be %26.
Full Text Searching can provide robust search capabilities on columns that have a Full Text Index. You are able to use the predicates CONTAINS and FREETEXT for this purpose.
In order to perform a Full Text Search,
Full Text Searching is currently only available for those using SQL Server 2016 or up.
CONTAINS is a predicate used in the WHERE clause of a CQL SELECT statement to perform full-text search on full-text indexed columns containing character-based data types.
CONTAINS can search for:
A word or phrase.
The prefix of a word or phrase.
A word near another word.
A word inflectionally generated from another (for example, the word drive is the inflectional stem of drives, drove, driving, and driven).
Using this general syntax without any modifiers, your results will return the specific rows that match the exact word or phrase specified between the single quotes in line 2.
In the following example, we want to return all rows from the Cinchy Wiki Documentation table (in the Product domain) that match the exact word overview in their Title column.
There are many modifiers you can add to your CONTAINS full text search query to receive more specific results.
Using a prefix term modifier will return results with your specified prefix. For example, the prefix 'over' could return overview, overture, overruled, etc.
To use a prefix term, wrap your term in single, then double quotes and put an asterix at the end: '"example*"'
In this example, we have modified our search so that we receive all results where the any word in the Title column contains the prefix 'over'.
A generation term modifier searches for all the different tenses and conjugations of a verb or both the singular and plural forms of a noun (an inflectional search) or for synonymous forms of a specific word (a thesaurus search).
In this example, our query will return all results with different tense and conjugations of our search word, 'gave'.
In this example, we want to return all results where the data in the Summary column matches the meaning of our search term.
I.E. "install" might return results with "deploy", "configure", "set", etc.
A proximity term will return words or phrases that are near to each other. You can also specify the maximum number of non-search terms that separate the first and last search terms.
Note that proximity terms in Cinchy do not adhere to the specified order written in the query. You will receive results of both "term 1+term 2" as well as "term 2+term 1".
This example returns all results where the terms "first" and "page" appear within two words of each other.
With CONTAINS, you can use AND, OR, and AND NOT to specify your results.
In this example, we want search results from the Summary column of the Cinchy Wiki Documentation page that contain both the word 'user' and the word 'page'.
In this example, we want search results from the Summary column of the Cinchy Wiki Documentation page that contain either the word 'user' or the word 'page'.
In this example, we want search results from the Summary column of the Cinchy Wiki Documentation page that contain the word 'user' and not the word 'page'.
You can use this modifier to return results with terms that appear near each other (i.e. within the same data cell).
In this example, we want to return all results where the data in the Title column has the term "data" appearing near the term "CinchyDXD".
The FREETEXT command provides the ability to search for a matched term based on the meaning of the terms as opposed to the exact character string.
At a high level, this commands finds matches based on separating the string into individual words, determining inflectional versions of the word and using a thesaurus to expand or replace the term to improve the search.
The difference between FREETEXT and CONTAINS is that it searches for the values that match the meaning of a phrase and not just exact words. It is therefore a better option if you are searching phrases, in lieu of individual words.
In this example, we want to return all results where the data in the Summary column matches the meaning of our search phrase.
I.E. "installation guide" might return results with "deployment instructions", "set up guide", etc.
The string functions covered in this section perform operations on a string (char or varchar) input value and return a string or numeric value.
ASCII (American Standard Code for Information Interchange) returns the ASCII code value of the leftmost character of a character expression.
This function converts an int between 0 to 255 to a character value. Outside of this range, the CHAR function will return a NULL value.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
integer_expression
An integer from 0 through 255.
char(1)
This function searches for one character expression inside another character string. If found, the function will return the starting position of the first expression.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
expressionToFind
The expression that needs to be found in the ExpressionString
expressionString
The string that contains the expression
start_Location
Start location from where the search will start
If CHARINDEX does not find expressionToFind within expressionString, CHARINDEX will return 0.
Returning the starting position of an expression
This example searches for a
in the string value.
Returning the starting position of an expression with an optional start location
This example searches for a
in the string value starting from 15th position.
The CONCAT function concatenates two or more string values one after the other. This function requires at least 2 strings and no more than 254 strings to concatenate.
string
A string to concatenate to the other strings.
string
A string with all the concatenated strings.
This function returns an integer value measuring the difference between the SOUNDEX () values of two different character expressions.strings.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
An alphanumeric expression of character data. string can be a constant, variable, or column.
int
Returns a value formatted with the specified format. Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general data type conversions, use CAST or CONVERT.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
value
Expression of a supported data type to format. For a list of valid types, see the table in the following Remarks section.
format
nvarchar format pattern.
The format argument must contain a valid .NET Framework format string, either as a standard format string (for example, "C" or "D"), or as a pattern of custom characters for dates and numeric values (for example, "MMMM DD, yyyy (dddd)").
nvarchar or null
The length of the return value is determined by the format.
The following table lists the acceptable data types for the value argument together with their .NET Framework mapping equivalent types.
FORMAT with strings
The following example shows formatting date values by specifying a custom format.
FORMAT with numerics
The following example shows formatting numeric values by specifying a custom format.
Returns the left part of a character string with the specified number of characters.
string
Is an expression of character or binary data. It can be of any data type, except text or ntext, that can be implicitly converted to varchar or nvarchar. Otherwise, use the CAST function to explicitly convert string.
integer
Is a positive integer that specifies how many characters of the string will be returned.
Returns a string
The following example returns the two leftmost characters from the string.
Returns the number of characters of the specified string expression, excluding trailing spaces.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
Is the string expression.
bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise, int.
The following example selects the number of characters and the data in string abcde
.
Returns a character expression after converting uppercase character data to lowercase.
string
Is an expression of character or binary data.
varchar or nvarchar
The following example uses the LOWER
function.
Returns a character expression after it removes leading blanks.
string
Is an expression of character or binary data.
varchar or nvarchar
Example: Using LTRIM
The following example uses LTRIM to remove leading spaces from a string
Returns the starting position of the first occurrence of a pattern in a specified expression.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
pattern
Is a character expression that contains the sequence to be found. Wildcard characters can be used; however, the % character must come before and follow pattern.
expression
Is an expression, typically a column that is searched for the specified pattern. expression is of the string data type category.
int or bigint
Example
The following example checks a short character string (this is a great day
) for the starting location of the characters eat
.
Replaces all occurrences of a specified string value with another string value.
string
Is the string expression to be searched.
string_toBeReplaced
Is the string to be found in the string.
string_replacedBy
Is the replacement string.
Returns nvarchar if one of the input arguments is of the nvarchar data type; otherwise, REPLACE returns varchar.
The following example replaces the string cde
in abcdefghi
with xyz
.
Returns the reverse order of a string value.
string
It is an expression of a string or binary data type.
varchar or nvarchar
The following example returns the reverse of the sting.
Returns the right part of a character string with the specified number of characters.
string
Is an expression of character or binary data.
integer
Is a positive integer that specifies how many characters of string will be returned.
Returns varchar when character_expression is a non-Unicode character data type.
Returns nvarchar when character_expression is a Unicode character data type.
Using RIGHT with a string
Returns a character string after truncating all trailing spaces.
string
Is an expression of character data.
varchar or nvarchar
The following example takes a string of characters that has spaces at the end of the sentence and returns the text without the spaces at the end of the sentence.
Returns a four-character (SOUNDEX) code to evaluate the similarity of two strings.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
Is an alphanumeric expression of character data. SOUNDEX converts an alphanumeric string to a four-character code that is based on how the string sounds when spoken.
varchar
The following example shows the standard SOUNDEX
values are returned for all consonants. Returning the SOUNDEX
for Raul
and Rahul
returns the same SOUNDEX result because all vowels, the letter y
, doubled letters, and the letter h
, are not included.
Returns a string of repeated spaces.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
integer_expression
Is a positive integer that indicates the number of spaces.
varchar
The following example concatenates a comma, two spaces, and the first name of the person.
Returns character data converted from numeric data. The character data is right-justified, with a specified length and decimal precision.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
float_expression
Is an expression of approximate numeric (float) data type with a decimal point.
length
Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.
decimal
Is the number of places to the right of the decimal point. decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point.
varchar
The following example converts an expression that is made up of five digits and a decimal point to a six-position character string. The fractional part of the number is rounded to one decimal place.
The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.
This function is not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
Is an expression of character data.
start
Is an integer value that specifies the location to start deletion and insertion.
length
Is an integer that specifies the number of characters to delete.
replaceWith
Is an expression of character data.
Returns character data if string is one of the supported character data types. Returns binary data if string is one of the supported binary data types.
The following example returns a character string created by deleting three characters from the first string, abcdef
, starting at position 2
, at b
, and inserting the second string at the deletion point.
Returns part of a character, binary, text, or image expression in SQL Server.
expression
Is a character, binary, text, ntext, or image expression.
start
Is an integer or bigint expression that specifies where the returned characters start.
length
Is a positive integer or bigint expression that specifies how many characters of the expression will be returned.
Returns character data if expression is one of the supported character data types. Returns binary data if expression is one of the supported binary data types. The returned string is the same type as the specified expression with the exceptions shown in the table.S
Example
The following example shows how to return only a part of a character string.
Returns a character expression with lowercase character data converted to uppercase.
string
Is an expression of character data.
varchar or nvarchar
The following example uses the UPPER
function to return the name in uppercase.
This page details the available JSON functions in Cinchy.The JSON functions covered in this section are:
These functions are not currently available in Postgres deployments.
This function tests whether a string contains valid JSON.
Argument | Description |
---|
Return Value | Description |
---|
This example will return all rows from the [Expression] column in the [Product].[Function Table] that contain valid JSON.
This example would return a 1 since the expression ('true') is valid JSON.
This functions extracts a scalar value from a JSON string.
Returns a single text value of type nvarchar(4000). The collation of the returned value is the same as the collation of the input expression.
The following example extracts the value of the JSON property into a local variable.
This function extracts an object or an array from a JSON string.
Returns a JSON fragment of type nvarchar(max). The collation of the returned value is the same as the collation of the input expression.
It would return the following result:
This function updates the value of a property in a JSON string and returns the updated JSON string.
Returns the updated value of expression as properly formatted JSON text.
The following example sets the surname to Smith.
It would return the following formatted JSON text:
Cinchy CQL supports the following on Open Geospatial Consortium (OGC) methods on geometry and geography instances.
Please note that all functions that have been denoted with Geometry in parenthesis are only applicable to OGC methods on geometry instances.
These function are not currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
You can review the full list of in-progress function translations.
The OGC Methods covered in this section are:
STArea()
returns the total surface area of a geometry/geography instance.
CQL: Number
When the geometry/geography instance contains only zero- and one-dimensional figures, or if it's empty, STArea()
returns 0.
This example creates a Polygon
geometry instance and computes the area of the Polygon:
This example creates a Polygon
geography instance and computes the area of the Polygon
:
STAsBinary()
returns the Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation of a geometry/geography instance.
CQL: Base64 Text
This example creates a LineString
geometry instance from (0,0) to (2,3) from text. STAsBinary()
returns the result in WKB:
This example uses STAsBinary()
to create a LineString
geography instance from (-122.360, 47.656) to (-122.343, 47.656) from text. It then returns the result in WKB:
STAsText()
returns the Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation of a geometry/geography instance.
CQL: Text
The return text will not containZ
(elevation) and M
(measure) values carried by the instance.
This example creates a LineString
geometry instance from (0,0) to (2,3) from text. STAsText()
returns the result in text:
This example uses STAsText()
to create a LineString
geography instance from (-122.360, 47.656) to (-122.343, 47.656) from text. It then returns the result in text:
STBoundary()
returns the boundary of a geometry instance.
CQL: geometry
This example uses STBoundary()
on a CurvePolygon
instance. STBoundary()
returns a CircularString
instance:
STBuffer()
returns a geometric/geography object that represents the union of all points whose distance from a geometry/geography instance is less than or equal to a specified value.
distance A value of type float (double in the .NET Framework) specifying the distance from the geometry/geography instance around which to calculate the buffer.
CQL: geometry/geography
STBuffer()
calculates a buffer specifying tolerance = distance * .001 and relative = false.
A negative buffer removes all points within the given distance of the boundary of the geometry/geography instance.
The error between the theoretical and computed buffer is max(tolerance, extents 1.E-7) where tolerance = distance * .001.
Geometry:
When distance > 0 then either a Polygon
or MultiPolygon
instance is returned. When distance = 0, then a copy of the calling geometry instance is returned. When distance < 0, then:
When the dimensions of the instance are 0 or 1, an empty GeometryCollection
instance is returned.
when the dimensions of the instance are 2 or more, a negative buffer is returned.
Geography:
STBuffer()
will return a FullGlobe
instance in certain cases; for example, STBuffer()
returns a FullGlobe
instance when the buffer distance is greater than the distance from the equator to the poles. A buffer cannot exceed the full globe.
This method will throw an ArgumentException
in FullGlobe
instances where the distance of the buffer exceeds the following limitation: 0.999 * π * minorAxis * minorAxis / majorAxis (~0.999 * 1/2 Earth's circumference).
This example returns a Polygon
instance with a negative buffer from a CurvePolygon
instance:
This example creates a LineString
geography instance. It then uses STBuffer()
to return the region within 1 meter of the instance:
STCentroid()
returns the geometry/geography center of a geometry/geography instance that consists of one or more Polygons
.
CQL: geometry/geography
If the geometry/geography instance is not a Polygon
, CurvePolygon
, or MultiPolygon
typeSTCentroid()
returns null.
This example uses STCentroid()
to compute the centroid of a polygon
geography instance:
STContains()
returns 1 if a geometry instance completely contains another geometry instance, returns 0 if it does not.
other_instance
Another geometry instance to compare against the instance on which STContains()
is invoked.
CQL: Yes/No
If the spatial reference IDs (SRIDs) of the geometry instances do not match, STContains()
always returns null.
This example uses STContains()
to test two geometry instances to see if the first instance contains the second instance:
STConvexHull()
returns an object representing the convex hull of a geometry instance.
CQL: geometry
Points or co-linear LineString
instances will produce an instance of the same type as that of the input. STConvexHull()
returns the smallest convex Polygon
that contains the given geometry instance.
This example uses STConvexHull()
to find the convex hull of a non-convex Polygon
geometry instance:
STCrosses()
returns 1 if a geometry instance crosses another geometry instance. Returns 0 if it does not.
other_instance
Another geometry/geography instance to compare against the instance on which STCrosses()
is invoked.
CQL: Yes/No
If the spatial reference IDs (SRIDs) of the geometry instances do not match, this method always returns null.
Both conditions must be true for two geometry instances to cross:
The intersection of the two geometry instances results in a geometry whose dimensions are less than the maximum dimension of the source geometry instances.
The intersection set is interior to both source geometry instances.
This example uses STCrosses()
to test two geometry instances to see if they cross:
STCurveToLine()
returns a polygonal approximation of a geometry instance that contains circular arc segments.
CQL: geometry
Returns null for uninitialized geometry variables
The polygonal approximation that the method returns depends on the geometry instance used to call the method:
Returns a LineString
instance for a CircularString
or CompoundCurve
instance.
Returns a Polygon
instance for a CurvePolygon
instance.
Returns a copy of the geometry instance if that instance is not a CircularString
, CompoundCurve
, or CurvePolygon
instance.
Any z-coordinate values present in the calling geometry instance are ignored.
In this example, the SELECT statement uses a LineString
instance to call the STCurveToLine
method. Thus, the method returns a LineString
instance:
STDifference()
returns an object that represents the point set from one geometry instance that does not lie within another geometry instance.
other_instance
Another geometry instance to compare against the instance on which STDifference()
is invoked.
CQL: geometry
Returns null if the spatial reference IDs (SRIDs) of the geometry instances do not match.
This example uses STDifference()
to compute the difference between two Polygons
:
STDisjoint()
returns 1 if a geometry instance is spatially disjoint from another geometry instance, returns 0 if it is not.
other_instance
Another geometry instance to compare against the instance on which STDisjoint()
is invoked.
CQL: Yes/No
If the intersection of the two geometry instances point sets are empty, they are disjoint.
Returns null if the spatial reference IDs (SRIDs) of the geometry instances do not match.
This example uses STDisjoint()
to test two geometry instances for spatial disjoint:
STDistance()
returns the shortest distance between a point in a geometry/geography instance and a point in another geometry/geography instance.
other_instance
Another geometry/geography instance to compare against the instance on which STDistance()
is invoked.
CQL: Number
STDistance()
always returns null if the spatial reference IDs (SRIDs) of the geometry/geography instances do not match.
This example finds the distance between two geometry instances:
This example finds the distance between two geography instances:
STEndPoint()
returns the end point of a geometry instance.
CQL: geometry
Returns null if called on an empty geometry instance.
STEnvelope()
returns the minimum axis-aligned bounding rectangle of the instance.
CQL: geometry
STEquals()
returns 1 if a geometry instance represents the same point set as another geometry instance, returns 0 if it does not.
other_instance
Another geometry instance to compare against the instance on which STEquals()
is invoked.
CQL: Yes/No
Returns null if the spatial reference IDs (SRIDs) of the geometry instances do not match.
STExteriorRing()
returns the exterior ring of a geometry instance that is a Polygon
.
CQL: geometry
Returns null if the geometry instance is not a Polygon
.
This example creates a polygon instance and uses STExteriorRing()
to return the exterior ring of the polygon as a LineString
:
STGeometryN()
returns a specified geometry in a geometry collection.
expression
Is an int expression between 1 and the number of geometry instances in the GeometryCollection
.
CQL: geometry
Returns null if the parameter is larger than the result of STGeometryN()
and will throw an ArgumentOutOfRangeException
if the expression parameter is less than 1.
This example creates a MultiPoint
GeometryCollection
and uses STGeometryN()
to find the second geometry instance of the collection:
STGeometryType()
returns the Open Geospatial Consortium (OGC) type name represented by geometry instance.
CQL: Text
The OGC type names that can be returned by STGeometryType()
are Point
, LineString
, CircularString
, CompoundCurve
, Polygon
, CurvePolygon
, GeometryCollection
, MultiPoint
, MultiLineString
, MultiPolygon
, and FullGlobe
.
This example creates a Polygon
instance and uses STGeometryType()
to confirm that it is a Polygon:
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STGeomCollFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
geometrycollection_tagged_text An nvarchar(max) expression that is the WKT representation of the geometry instance you wish to return.
SRID An int expression representing the spatial reference ID (SRID) of the geometry instance you wish to return.
CQL: geometry
The OGC type of the geometry instance returned by STGeomCollFromText()
is set to the corresponding WKT input.
Throws an ArgumentException
if the input is not valid.
This example uses STGeomCollFromText()
to create a geometry instance:
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STGeomFromText()
returns a geometry/geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
inctance_tagged_text An nvarchar(max) expression that is the WKT representation of the geometry/geography instance you wish to return.
SRID An int expression representing the spatial reference ID (SRID) of the geometry/geography instance you wish to return.
CQL: geometry/geography
The OGC type of the geometry/geography instance returned by STGeomFromText()
is set to the corresponding WKT input.
If the input isn't well-formatted, method will throw a FormatException
.
Geography:
Throws an ArgumentException
if the input contains an antipodal edge.
This example uses STGeomFromText()
to create a geometry instance:
This example uses STGeomCollFromText()
to create a geography instance:
STGeomFromWKB()
returns a geometry/geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
WKB_instance An nvarchar(max) expression that is the WKB representation of the geometry/geography instance to return.
SRID An int expression representing the spatial reference ID (SRID) of the geometry/geography instance to return.
CQL: geometry/geography
The OGC type of the geometry/geography instance returned by STGeomFromWKB()
is set to the corresponding WKB input.
If the input isn't well-formatted, method will throw a FormatException
.
Geography:
Throws an ArgumentException
if the input contains an antipodal edge.
This example uses STGeomFromWKB()
to create a geometry instance:
This example uses STGeomFromWKB()
to create a geography instance:
STInteriorRingN()
returns the specified interior ring of a Polygon
geometry instance.
expression An int expression between 1 and the number of interior rings in the geometry instance.
CQL: geometry
Returns null if the geometry instance is not a Polygon
.
This example creates a Polygon
instance and uses STInteriorRingN()
to return the interior ring of the Polygon
as a LineString
:
STIntersection()
returns an object that represents the points where a geometry/geography instance intersects another geometry/geography instance.
other_instance
Another geometry/geography instance to compare against the instance on which STIntersection()
is invoked.
CQL: geometry/geography
If the spatial reference IDs (SRIDs) of the geometry/geography instances do not match, STIntersection()
always returns null.
The result may contain circular arc segments only if the input instances contain them.
This example uses STIntersection()
to compute the intersection of two polygons:
This example uses STIntersection()
to compute the intersection of a Polygon
and a LineString:
STIntersects()
returns 1 if a geometry instance intersects another geometry instance. Returns 0 if it does not.
other_instance
Another geometry/geography instance to compare against the instance on which STIntersects()
is invoked.
CQL: Yes/No
Returns null if the spatial reference IDs (SRIDs) of the geometry/geography instances do not match.
This example uses STIntersects()
to determine if two geometry instances intersect each other:
This example uses STIntersects()
to determine whether two geography instances intersect each other:
STIsClosed()
returns 1 if the start and end points of the given geometry instance are the same. Returns 1 for GeometryCollection
types if each contained geometry instance is closed. Returns 0 if the instance is not closed.
CQL: Yes/No
Returns 0 if any figures of a geometry instance are points, or if the instance is empty.
All Polygon
instances are considered closed.
This example creates a LineString
instance and uses STIsClosed()
to test if the LineString
is closed:
STIsEmpty()
returns 1 if a geometry instance is empty. Returns 0 if a geometry instance is not empty.
CQL: Yes/No
This example creates an empty geometry instance and uses STIsEmpty()
to test whether the instance is empty:
STIsRing()
returns 1 if a geometry instance fulfills the following requirements:
It is a LineString
instance.
It is closed (for a geometry to be closed, STIsClosed() needs to return 1 when invoked on the instance).
It is simple (for a geometry to be simple, STIsSimple() needs to return 1 when invoked on the instance).
Returns 0 if the LineString
instance does not meet the requirements.
CQL: Yes/No
Returns null if the instance is not a LineString
.
This example creates a LineString
instance and uses STIsRing()
to test whether the instance is a ring:
STIsSimple()
returns 1 if a geometry instance is simple, as defined by the Open Geospatial Consortium (OGC). Returns 0 if a geometry instance is not simple.
CQL: Yes/No
To be simple a geometry instance must meet the requirements:
Except at the endpoints, each figure of the instance must not intersect itself.
No two figures of the instance can intersect each other at a point that is not in both of their boundaries.
This example creates a non-simple LineString
instance that intersects itself and uses STIsSimple()
to test whether the LineString
is simple:
STIsValid()
returns true if a geometry instance is well-formed, based on its Open Geospatial Consortium (OGC) type. Returns false if a geometry instance is not well-formed.
CQL: Yes/No
SQL Server produces only valid geometry instances, but allows for the storage and retrieval of invalid instances.
This example creates a geometry instance and uses STIsValid()
to test if the instance is valid:
STLength()
returns the total length of the elements in a geometry/geography instance or the geometry/geography instances within a GeometryCollection
.
CQL: Yes/No
If a geometry/geography instance is closed, its length is calculated as the total length around the instance
The length of a GeometryCollection
is found by calculating the sum of the lengths of all of the geometry/geography instances contained within the collection.
STLength()
works on both valid and invalid LineString
.
This example creates a LineString
instance and uses STLength()
to find the length of the instance:
This example creates a LineString
instance and uses STLength()
to find the length of the instance:
Augmented with any Z
(elevation) and M
(measure) values carried by the instance,STLineFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
linestring_tagged_text
An nvarchar(max) expression that is the WKT representation of the geometry LineString
instance you wish to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometry LineString
instance you want to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example uses STLineFromText()
to create a geometry instance:
STLineFromWKB()
returns a geometry LineString
instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
WKB_linestring
A varbinary(max) expression that is the WKB representation of the geometry LineString
instance to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometry LineString
instance you want to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example uses STLineFromWKB()
to create a geometry instance:
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STMLineFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
multilinestring_tagged_text
An nvarchar(max) expression that is the WKT representation of the geometryMultiLineString
instance you wish to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometry MultiLineString
instance you wish to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example uses STMLineFromText()
to create a geometry instance:
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STMPointFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
multipoint_tagged_text
An nvarchar(max) expression that is the WKT representation of the geometry MultiPoint
instance you wish to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometryMultiPoint
instance you wish to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example uses STMPointFromText()
to create a geometry instance:
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STMPolyFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
multipolygon_tagged_text
An nvarchar(max) expression that is the WKT representation of the geometry MultiPolygon
instance you wish to return.
SRID
Is an int expression representing the spatial reference ID (SRID) of the geometry MultiPolygon
instance you wish to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example usesSTMPolyFromText()
to create a geometry instance:
STNumCurves()
returns the number of curves in a one-dimensional geometry instance.
CQL: geometry
An empty one-dimensional geometry instance returns 0.
Null is returned when the geometry instance is not a one-dimensional instance or is an uninitialized instance.
One-dimensional spatial data types include LineString
, CircularString
, and CompoundCurve
. STNumCurves()
works only on simple types; it does not work with geometry collections like MultiLineString
.
This example shows how to get the number of curves in a CircularString
instance:
STNumGeometries()
returns the number of geometries that comprise a geometry instance.
CQL: Number
This method returns 1 if the geometry instance is not a MultiPoint
, MultiLineString
, MultiPolygon
, or GeometryCollection
instance, and 0 if the geometry instance is empty.
This example creates a MultiPoint
instance and uses STNumGeometries()
to find out how many geometries the instance contains:
STNumInteriorRing()
returns the number of interior rings of a Polygon
geometry instance.
CQL: Number
Returns null if the geometry instance is not a Polygon
.
This example creates a Polygon
instance and uses STNumInteriorRing()
to find how many interior rings the instance has:
STNumPoints()
returns the sum of the number of points in each of the figures in a geometry instance.
CQL: Number
STNumPoints()
counts the points (duplicate points are counted) in the description of a geometry instance. If this instance is a collection type, this method returns the sum of the points in each of its elements.
This example creates a LineString
instance and uses STNumPoints()
to determine how many points were used in the description of the instance:
STOveralps()
returns 1 if a geometry instance overlaps another geometry instance. Returns 0 if it does not.
other_instance
Another geometry instance to compare against the instance on which STOverlaps()
is invoked.
CQL: Yes/No
If the points where the geometry instances intersect are not in the same dimension, STOverlaps()
always returns 0.
If the spatial reference IDs (SRIDs) of the geometry instances do not match, STOverlaps()
returns null.
Two geometry instances overlap if the region representing their intersection has the same dimension as the instances do and the region does not equal either instance.
This example uses STOverlaps()
to test two geometry instances for overlap:
Only available in SQLServer implementations.
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STPointFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
point_tagged_text
An nvarchar(max) expression that is the WKT representation of the geometry Point
instance you wish to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometry Point
instance you wish to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example usesSTPointFromText()
to create a geometry instance:
STPointFromWKB()
returns a geometry Point instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
WKB_point
A varbinary(max) expression that is the WKB representation of the geometry Point
instance you wish to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometry Point
instance you wish to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example usesSTPointFromWKB()
to create a geometry instance:
STPointN()
returns a specified point in a geometry instance.
expression An int expression between 1 and the number of points in the geometry instance.
CQL: geometry
Throws an ArgumentOutOfRangeException
, if this method is called with a value less than 1.
Returns null if this method is called with a value greater than the number of points in the instance.
STPointN()
returns the point specified by expression, if a geometry instance is user created. (occurs by ordering the points in which they were originally input).
STPointN()
returns the point specified by expression, if a geometry instance was constructed by the system (by ordering all the points in the same order they would be output: first by geometry, then by ring within the instance (if appropriate), and then by point within the ring).
This example creates a LineString
instance and uses STPointN()
to retrieve the second point in the description of the instance:
STPointOnSurface()
returns an arbitrary point located within the interior of a geometry instance.
CQL: geometry
If the instance is empty, method returns null.
This example creates a Polygon
instance and uses STPointOnSurface()
to find a point on the instance:
Only available in SQLServer implementations.
Augmented with any Z
(elevation) and M
(measure) values carried by the instance, STPolyFromText()
returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
polygon_tagged_text
An nvarchar(max) expression that is the WKT representation of the geometry Polygon
instance you wish to return.
SRID
An int expression representing the spatial reference ID (SRID) of the geometry Polygon
instance you wish to return.
CQL: geometry
If the input isn't well-formatted, method will throw a FormatException
.
This example usesSTPolyFromText()
to create a geometry instance:
STRelate()
returns 1 if a geometry instance is related to another geometry instance, otherwise, returns 0. (The relationship between the geometry instances is defined by a Dimensionally Extended 9 Intersection Model (DE-9IM) pattern matrix value)
other_instance
Another geometry instance to compare against the instance on which STRelate()
is invoked.
intersection_pattern_matrix Is a string of type nchar(9) encoding acceptable values for the DE-9IM pattern matrix device between the two geometry instances.
CQL: Yes/No
If the spatial reference IDs (SRIDs) of the geometry instances do not match, method returns null.
If matrix is not well-formed, an ArgumentException
will be thrown.
This example uses STRelate()
to test two geometry instances for spatial disjoint using an explicit DE-9IM pattern:
STStartPoint()
returns the start point of a geometry instance.
CQL: geometry
This example uses STStartPoint()
to retrieve the start point of the instance and creates a LineString
instance:
STSymDifference()
returns an object that represents all points that are either in one geometry instance or another geometry instance, but not those points that lie in both instances.
other_instance
Another geometry instance to compare against the instance on which STSymDifference()
is invoked.
CQL: geometry/geography
If the spatial reference IDs (SRIDs) of the geometry instances do not match, method returns null.
Result may contain circular arc segments (only if the input instances contain circular arc segments).
This example uses STSymDifference()
to compute the symmetric difference of two Polygon
instances:
STTouches()
returns 1 if a geometry instance spatially touches another geometry instance. Returns 0 if it does not.
other_instance
Another geometry instance to compare against the instance on which STTouches()
is invoked.
CQL: Yes/No
If two geometry instances point sets intersect, they are touching but their interiors do not intersect.
If the spatial reference IDs (SRIDs) of the geometry instances do not match, method returns null.
This example uses STTouches()
to test two geometry
instances to see if they touch:
STUnion()
returns an object that represents the union of a geometry instance with another geometry instance.
other_instance
Another geometry instance to compare against the instance on which STUnion()
is invoked.
CQL: geometry
If the spatial reference IDs (SRIDs) of the geometry instances do not match, method returns null.
Result may contain circular arc segments (only if the input instances contain circular arc segments).
This example uses STUnion()
to compute the union of two Polygon
instances:
STWithin()
returns 1 if a geometry instance is completely within another geometry instance; otherwise, returns 0.
other_instance
Another geometry instance to compare against the instance on which STWithin()
is invoked.
CQL: Yes/No
The STWithin
command is case-sensitive.
If the spatial reference IDs (SRIDs) of the geometry instances do not match, method returns null.
This example uses STWithin()
to test two geometry
instances to see if the first instance is completely within the second instance:
You can review the full list of in-progress function translations
You can review the full list of in-progress function translations
You can review the full list of in-progress function translations
Argument | Description |
---|
In order to return the synonymous forms, you must have a Thesaurus file configured.
In order to use FREETEXT, you must have a Thesaurus file configured.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
You can review the full list of in-progress function translations.
Argument | Description |
---|
Argument | Description |
---|
Argument | Description |
---|
OGC type of a geography instance can be determined by invoking
STEndPoint()
is the equivalent of .
This example creates a LineString
instance with and uses STEndpoint()
to retrieve the end point of the LineString:
This example uses to create a LineString
instance from (0,0) to (2,3), and uses STEnvelope()
to return the bounding box of the LineString:
This example creates two geometry instances with that are equal but not trivially equal, and uses STEquals()
to test their equality:
This method will throw an ArgumentOutOfRangeException
if the expression is larger than the number of rings. The number of rings can be returned using .
The OGC type of a geometry instance can be determined by invoking .
STStartPoint()
is the equivalent of .
datepart
year
quarter
month
dayofyear
day
week
hour
minute
second
millisecond
microsecond
nanosecond
datepart name
year
quarter
month
dayofyear
day
week
hour
minute
second
millisecond
microsecond
nanosecond
datepart
year
quarter
month
dayofyear
day
week
weekday
hour
minute
second
millisecond
microsecond
nanosecond
datepart
year
quarter
month
dayofyear
day
week
weekday
hour
minute
second
millisecond
microsecond
nanosecond
TZoffset
ISO_WEEK
datepart
Return value
year
2007
quarter
4
month
October
dayofyear
303
day
30
week
44
weekday
Tuesday
hour
12
minute
15
second
32
millisecond
123
microsecond
123456
nanosecond
123456700
TZoffset
+05:10
ISO_WEEK
44
Return Value
Description
24400
Valid
24401
Not valid, reason unknown.
24402
Not valid because point {0} is an isolated point, which is not valid in this type of object.
24403
Not valid because some pair of polygon edges overlap.
24404
Not valid because polygon ring {0} intersects itself or some other ring.
24405
Not valid because some polygon ring intersects itself or some other ring.
24406
Not valid because curve {0} degenerates to a point.
24407
Not valid because polygon ring {0} collapses to a line at point {1}.
24408
Not valid because polygon ring {0} is not closed.
24409
Not valid because some portion of polygon ring {0} lies in the interior of a polygon.
24410
Not valid because ring {0} is the first ring in a polygon of which it is not the exterior ring.
24411
Not valid because ring {0} lies outside the exterior ring {1} of its polygon.
24412
Not valid because the interior of a polygon with rings {0} and {1} is not connected.
24413
Not valid because of two overlapping edges in curve {0}.
24414
Not valid because an edge of curve {0} overlaps an edge of curve {1}.
24415
Not valid some polygon has an invalid ring structure.
24416
Not valid because in curve {0} the edge that starts at point {1} is either a line or a degenerate arc with antipodal endpoints
Input type | Return type |
float, real | float |
decimal(p, s) | decimal(38, s) |
int, smallint, tinyint | int |
bigint | bigint |
money, smallmoney | money |
bit, char, nchar, varchar, nvarchar | float |
Expression result | Return type |
tinyint | int |
smallint | int |
int | int |
bigint | bigint |
decimal and numeric category (p, s) | decimal(p, s) |
money and smallmoney category | money |
float and real category | float |
Examples | Results |
ROUND(748.58, -4) | 0 |
Examples | Restuls |
ROUND(748.58, -1) | 750.00 |
ROUND(748.58, -2) | 700.00 |
ROUND(748.58, -3) | Results in an arithmetic overflow, because 748.58 defaults to decimal(5,2), which cannot return 1000.00. |
To round up to 4 digits, change the data type of the input. For example:
| 1000.00 |
Specified expression | Return type |
bigint | bigint |
int/smallint/tinyint | int |
money/smallmoney | money |
numeric/decimal | numeric/decimal |
Other types | float |
Parameter | The parameter value that you want to escape in order to be safe to use inside a URL without breaking it |
Category | Type | .NET type |
Numeric | bigint | Int64 |
Numeric | int | Int32 |
Numeric | smallint | Int16 |
Numeric | tinyint | Byte |
Numeric | decimal | SqlDecimal |
Numeric | numeric | SqlDecimal |
Numeric | float | Double |
Numeric | real | Single |
Numeric | smallmoney | Decimal |
Numeric | money | Decimal |
Date and Time | date | DateTime |
Date and Time | time | TimeSpan |
Date and Time | datetime | DateTime |
Date and Time | smalldatetime | DateTime |
Date and Time | datetime2 | DateTime |
Date and Time | datetimeoffset | DateTimeOffset |
Expression | The string to test. |
1 | Returned if the input is a valid JSON object or array. |
0 | Returned if the input is not a valid JSON object of array. |
Null | Returned if the expression is null. |
| | |
|
| | | |
| | |
Expression | An expression. Typically the name of a variable or a column that contains JSON text. If JSON_VALUE finds JSON that is not valid in expression before it finds the value identified by path, the function returns an error. If JSON_VALUE doesn't find the value identified by path, it scans the entire text and returns an error if it finds JSON that is not valid anywhere in expression. |
Path |
Expression | An expression. Typically the name of a variable or a column that contains JSON text. If JSON_QUERY finds JSON that is not valid in expression before it finds the value identified by path, the function returns an error. If JSON_QUERY doesn't find the value identified by path, it scans the entire text and returns an error if it finds JSON that is not valid anywhere in expression. |
Path | It follows zero-based indexing. Using employees[0] will return the first value in our JSON. If the format of path isn't valid, JSON_QUERY returns an error. |
Expression | An expression. Typically the name of a variable or a column that contains JSON text. JSON_MODIFY returns an error if expression doesn't contain valid JSON. |
Path |
|
newValue | The new value for the property specified by path. The new value must be a [n]varchar or text. |
Parameter | The parameter value that you want to escape in order to be safe to use inside a JSON document without breaking it |
A that specifies the property to extract. If the format of path isn't valid, JSON_VALUE returns an error.
A that specifies the property to extract. The default value for path is '$'. As a result, if you don't provide a value for path, JSON_QUERY returns the input expression.
A that specifies the property to extract. It takes the following format:
<json path> Specifies the path for the property to update. For more info, see . JSON_MODIFY returns an error if the format of path isn't valid.