Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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 Query Language (CQL) statements are grouped into two (2) categories:
Data Manipulation Language (DML) - DML is used to add, retrieve, update and manipulate data. For example, insert, update, delete.
Data Definition Language (DDL) - DDL is used to create a database schema and define constraints. For example, create a table and alter a table.
List of available DML statements:
List of available DDL statements:
DML is used to add, retrieve, update and manipulate data.The Cinchy DML statements covered on this page are:
IF
The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.
Note: Table name requires domain prefix.
Syntax
Example
You can create a query that will produce a nested JSON by wrapping it in an outer SELECT statement, such as in the example below.
Note that you should set the return type to "Single Value (First Column of First Row)".
An INSERT statement can be used to add new rows to a table or view
You can also include a SELECT statement to identify that another table or view contains the data for the new row or rows.
Note: The table name requires the domain prefix.
Syntax
Example
The data in a table can be changed by using the UPDATE statement.
The UPDATE statement modifies zero or more rows of a table, depending on how many rows satisfy the search condition that was specified in the WHERE clause.
An UPDATE statement can also be used to specify the values that are to be updated in a single row.
This is done by specifying constants, host variables, expressions, DEFAULT, or NULL. Specify NULL to remove a value from a row's column (without removing the row).
Note: Table name requires domain prefix.
Syntax
Example
A DELETE statement can be used to remove entire rows from a table. The number of rows deleted depends on how many rows satisfy the search condition specified in the WHERE statement.
Note: Table name requires domain prefix.
Syntax
Example
The IF statement is used to execute a condition. If the condition is satisfied then the boolean expressions returns TRUE value. The optional ELSE keyword introduces another statement that is executed when the IF condition is not satisfied and returns FALSE value.
Syntax
Example
The DECLARE statement is used to declare a variable.
Syntax
Example
The SET variable is used to set a value to a variable.
Syntax
Example
This page provides some examples of Cinchy Query Language in action.
The following section breaks down some example queries for you to get a feel for the power of CQL and how to use it. These are just simple examples, but will provide you with a jumping off point for creating your own, more complex queries.
For more information on saved queries, see our Builder Guide, here.
This query is useful for pulling a list of specific user information from a table. This query will return a list with Names (which will be returned under the 'Full Name' label), Emails, and Companies of the users listed in the [Contacts].[People] table. We have stipulated to only include entries where the [Name] is not null, and where the [Tags].[Name] column is set to 'Analyst'
In this example we want to find all System Tables in our instance. System Tables come pre-packaged with Cinchy and live under the 'Cinchy' domain. You can query for a list of them using the below CQL, where we are pulling the 'Name' column from the [Tables] table, in the [Cinchy] Domain. We have added a filter to only return results where the table [Domain] is tagged as 'Cinchy'.
In this example, we want to generate a list of the system columns attached to the [Policies] table in the [Compliance] domain. We do so by putting the * symbol in the SELECT statement. We have also added an option ORDER BY clause, to order our results based on the input values.
In this example, we have a table with a view for "My Open Tasks". We want this view to only show tasks that are assigned to the currently logged in user, so we would use currentuserID=().
The below query is used to find the creator of any specific table, based on its tablecinchyid. We are pulling the Table Name and the Created By user information from the [Cinchy].[Tables] table. By using [Cinchy Id] = @tablecinchyid, a search box will appear when we run this query, where you can insert the Table ID number of the table you are curious about.
In the below example, we are using a query to return a list of all tables created by a specific user. We are pulling the Full Name of the table and the name of the creator from the [Cinchy].[Tables] table. By using [Created By].[Name] = @author, running the query will generate a search box where you can write in the full name of the user you are searching for information on.
If/Else statements can be used in CQL to specify conditions. In the below example, we are using a query to vote for user awards, and our IF statements are looking for the currentuserid() to determine the results of the query.
If the current user is the same as the nominated user, the query will return a message stating "Hey! No voting for yourself!"
Our second condition checks whether the current user is the same as the user who created the nomination. In this case, the query will return a message stating "Hey! No voting for your own nomination!"
If neither of the two IF statements apply, the final ELSE is triggered to capture the vote (using the INSERT INTO statement), and a message is returned stating "Your vote has been recorded. Great work!"
This query returns the Name, Domain, and timestamp of deletion for all tables within [Cinchy].[Tables] where [Deleted] IS NOT NULL. We have added an option WHERE clause to ignore any data from the 'Sandbox' Domain.
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):
This page will help you to understand the fundamentals of getting started with Cinchy Query Language.
Cinchy Query Language (CQL) is a query language unique to dataware that is used to retrieve and manage/modify data and metadata from tables in your network. While data can reside across many tables, a query can isolate it to a single output, making the possibilities of CQL endlessly powerful.
Cinchy Query Language can be used in many ways, including but not limited to:
Building queries through the query editor that can return, insert, delete, and otherwise manage your data.
Creating, altering or dropping views for tables
Creating, altering or dropping indexes
For an overview of the supported functions of CQL,
All queries on Cinchy are automatically protected by universal data access controls. This means that if you run a CQL query, you will only see the data that you have been given access to.
The following is a non-exhaustive list of some of the common things to keep in mind while using CQL. While CQL pulls many similarities to other queries languages such as SQL or PGSQL that you may already be familiar with, there are still differences to make note of.
Cinchy comes with an intuitive Query Builder UI. When using the builder, the below basic syntax is pre-written for you. You can then use the drag and drop interface or type in your own search terms to build your query.
In all queries built using the Cinchy Query Builder, you will note that it includes a "WHERE [Deleted] IS NULL" clause. This will prevent any data that has been deleted from a table from ending up in your query. If you want to include deleted data, you must delete this clause.
When querying a table, you must use the [Domain].[Table] syntax. For example, to query the Product Content Backlog table, you would use [Product].[Product Content Backlog].
When querying a linked column, you must similarly use the [Column Name].[Linked Column Name] syntax.
For example, in the below query we are pulling from the [Product].[Product Content Backlog] table, and are looking for data from a linked column called "Requester", which points to the Users table. In order to return the [Full Name] column from the linked Users table, we must use the [Requester].[Full Name] syntax.
Multi-level links are also possible using a similar syntax of [Column Name].[Linked Column Name].[Linked Column Name]. For example, if you wanted to see the Manager ID of a specific employee, you could use [Employee].[Reports To].[Employee ID], which will find the Employee in question, then who they report to, then the ID number of that person.
When writing queries, single notation marks are used to denote string/text data. For example, if you wanted to specify the Sandbox domain, you would use [Domain] = 'Sandbox'
When trying to query using a "does not equal" syntax, you would use !=. For example, the following denotes to only return results where the [Domain] does not equal 'Sandbox'
If you want to query data from a table where certain rows are still in draft/Create Request format, you would use the syntax of Draft([Column Name]) to see the draft changes. Make sure to also include [Column Name] as well to include non-draft rows.
The default ORDER BY function will always set ascending unless specified.
When using a boolean query, 1 = true, and 0 = false.
Version history in Cinchy is labeled differently in other SQL systems. Normally a version history is shown through, for example, "version 1.2.4". Cinchy follows these conventions but splits them up. The two ORDER BY options, Version and Draft Data. are the version numbers. Version is the first number, and Draft Data is the second number in the sequence Example: [Version]: 2 and [Draft Data]: 5 means the overall version of the policy is 2.5
If there is an error in your CQL code an error message will appear in your Query Results in the query builder indicating what column and row your error(s) reside in.
When using an INSERT INTO clause, the order of the columns input must match the same order as in the VALUES section.
Putting a * symbol after a SELECT statement in the Query Builder will return a series of system columns attached to each table entry.
Use RESOLVELINK when inserting or updating values for link columns. In the below example, we use (RESOLVELINK(@Manager,'Full Name')) because the Manager column is a linked column pulling from the Employee table. The syntax for using Resolve Link is: ResolveLink('value(s)','column in target table')
You can specify what your results return as in the Query Builder
The following tables provide the data type(s) that a Cinchy Data Type translates to in the database:
DDL is used to create a database schema and define constraints.The Cinchy DDL functions covered on this page are:
The following tables provide the data type(s) that a Cinchy Data Type translates to in the database:
The CREATE TABLE statement is used to create a new table in a database.
The column parameters specify the names of the columns of the table.The datatype parameter specifies the type of data the column can hold (e.g. varchar, char, int, date, etc.).
Syntax
Example
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
Syntax
Example
The DROP TABLE statement is used to drop an existing table in a database.
Syntax
Example
In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, taken from fields of an original table and presents them with a different structure and organization. For example, this is useful when only some columns of a table may be relevant to a user, so they don't have to see information from other columns that may be irrelevant to them.
SQL functions and the WHERE statement can be added to a view to present the data as if the data was coming from one single table.
Syntax
Example
Modifies a previously created view. This includes an indexed view. ALTER VIEW does not affect dependent stored procedures or triggers and does not change permissions.
Syntax
Example
A view is deleted with the DROP VIEW command.
Syntax
Example
Syntax
Example
The DROP INDEX statement is used to delete an index on a table.
Syntax
Example
The CREATE INDEX statement is used to create in tables.
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 |
Query Return Results | Description |
Query Result (Approved Data Only) (*This is the default when creating a new query) | This is the default return type, it returns a table from a select query with only approved data for Maker/Checker-enabled tables, or all data for tables without Maker/Checker-enabled. This is generally used for external APIs as you will want to query approved data, rather than drafts. |
Query Result (Including Draft Data) | This return type returns a table from a select query with only draft data for Maker/Checker-enabled tables. Use this return type when looking to display results of records that are pending approval. |
Query Result (Including Version History) | This return type returns a table from a select query with historical data for all tables, as seen in the Collaboration Log of any record. This data includes all changes that happened to all records within the scope of the select query. |
Number of Rows Affected | This return type returns a single string response with the number of rows affected if the last statement in the query is an INSERT, UPDATE, or DELETE statement. |
Execute DDL Script | Use this return type when your query contains DDL commands that implement schema changes such as CREATE|ALTER|DROP TABLE, CREATE|ALTER|DROP VIEW, or CREATE|DROP INDEX. |
Single Value (First Column of First Row) | This return type returns a result of 1 row x 1 column, irrespective of the underlying result set. |
Number | Text | Date |
Int | NVarChar | DateTime |
BigInt | VarChar | Date |
Decimal | Char | |
Float | NChar | |
Money | NText | |
Numeric | Text | |
Real | | |
SmallInt | | |
SmallMoney | | |
TinyInt | | |
Binary | Text |
VarBinary | Bit |
Binary | Yes/No |
VarBinary | Bit |
Number | Text | Date |
Int | NVarChar | DateTime |
BigInt | VarChar | Date |
Decimal | Char | |
Float | NChar | |
Money | NText | |
Numeric | Text | |
Real | | |
SmallInt | | |
SmallMoney | | |
TinyInt | | |
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 following living list documents Cinchy Query Language functions. Click on the function name to be taken to its individual documentation page.Please note that some CQL functions are currently "in progress" for support on PGSQL deployments. Please check back regularly for the updated list.
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):
Table-Valued Functions - 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.
Scalar-Valued Functions - 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 https://github.com/sebastienros/jint, which uses ECMAScript 5.1.
If you are having issues with your script, we suggest pasting it into https://jshint.com/, a tool that helps to detect errors and potential problems in your JavaScript code, as it also runs ECMAScript 5.1.
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.
Perform operations on a date and time input values and return string, numeric, or date and time values.
The date and time date type and functions covered in this section are:
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
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.
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.
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.
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.
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 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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Method | Description |
---|---|
Method | Description |
---|---|
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.
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.
Function Name
Description
TSQL Support
PGSQL Support
Returns the absolute (positive) value of the specified numeric expression.
Supported
Supported
Returns the angle, in radians, whose cosine is the specified float expression.
Supported
Supported
Returns the ASCII code value of the leftmost character of a character expression.
Supported
Supported
Returns the angle, in radians, whose sine is the specified float expression.
Supported
Supported
Returns the angle, in radians, whose tangent is a specified float expression.
Supported
Supported
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.
Supported
Supported
Used with CONVERT to convert an expression of one data type to another.
Supported
In Progress
CEILING
Returns the smallest integer greater than, or equal to, the specified numeric expression.
Supported
Supported
Converts an int between 0 to 255 to a character value.
Supported
In Progress
Searches for one character expression inside another character string. If found, the function will return the starting position of the first expression.
Supported
In Progress
Returns an item at the specified index from a list of values in Cinchy.
Supported
In Progress
Concatenates two or more string values one after the other.
Supported
Supported
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.
Supported
In Progress
Used with CAST to convert an expression of one data type to another.
Supported
In Progress
COS
Returns the trigonometric cosine of the specified angle - measured in radians - in the specified expression.
Supported
Supported
COT
Returns the trigonometric cotangent of the specified angle - in radians - in the specified float expression.
Supported
Supported
Adds a specified number value to a specified datepart of an input date value, and then returns that modified value.
Supported
In Progress
Returns the count of the specified datepart boundaries crossed between the specified startdate and enddate.
Supported
In Progress
Returns the count of the specified datepart boundaries crossed between the specified startdate and enddate.
Supported
In Progress
Returns a character string representing the specified datepart of the specified date.
Supported
In Progress
Returns an integer representing the specified datepart of the specified date.
Supported
In Progress
Returns a date value that maps to the specified year, month, and day values.
Supported
In Progress
Returns a datetime value for the specified date and time arguments.
Supported
In Progress
Returns a datetime2 value for the specified date and time arguments.
Supported
In Progress
Returns a datetimeoffset value for the specified date and time arguments.
Supported
In Progress
Returns an integer that represents the day (day of the month) of the specified date.
Supported
In Progress
Returns an integer value measuring the difference between the SOUNDEX () values of two different character expression strings.
Supported
In Progress
Returns the corresponding angle, in degrees, for an angle specified in radians.
Supported
Supported
Returns the last day of the month containing a specified date, with an optional offset.
Supported
In Progress
Returns the exponential value of the specified float expression.
Supported
Supported
Returns the largest integer less than or equal to the specified numeric expression.
Supported
Supported
Returns a value formatted with the specified format.
Supported
In Progress
Provides the ability to search for a matched term based on the meaning of the terms as opposed to the exact character string.
Supported
In Progress
Returns one of two values which is depending on if the Boolean expression evaluates TRUE or FALSE in the Cinchy.
Supported
In Progress
Returns a message that can help to identify problems with a spatial object that is not valid.
Supported
In Progress
Checks an expression to see if it is correct.
Supported
In Progress
Tests whether a string contains valid JSON.
Supported
In Progress
Updates the value of a property in a JSON string and returns the updated JSON string.
Supported
In Progress
Extracts an object or an array from a JSON string.
Supported
In Progress
Extracts a scalar value from a JSON string.
Supported
In Progress
Returns the left part of a character string with the specified number of characters.
Supported
Supported
LEN
Returns the number of characters of the specified string expression, excluding trailing spaces.
Supported
In Progress
Returns the natural logarithm of the specified float expression in SQL Server.
Supported
In Progress
LOG10
Returns the base-10 logarithm of the specified float expression.
Supported
Supported
Returns a character expression after converting uppercase character data to lowercase.
Supported
Supported
Returns a character expression after it removes leading blanks.
Supported
Supported
Converts an invalid geometry instance into a geometry instance with a valid Open Geospatial Consortium (OGC) type.
Supported
In Progress
Returns an integer that represents the month of the specified date.
Supported
In Progress
Returns the starting position of the first occurrence of a pattern in a specified expression.
Supported
In Progress
Returns the constant value of PI.
Supported
Supported
Returns the value of the specified expression to the specified power.
Supported
Supported
Returns radians when a numeric expression, in degrees, is entered.
Supported
In Progress
Returns a pseudo-random float value from 0 through 1, exclusive.
Supported
In Progress
Returns an approximation of the given geometry instance produced.
Supported
In Progress
Replaces all occurrences of a specified string value with another string value.
Supported
Supported
Returns the reverse order of a string value.
Supported
Supported
Returns the right part of a character string with the specified number of characters.
Supported
Supported
ROUND
Returns a numeric value, rounded to the specified length or precision.
Supported
Supported
Returns a character string after truncating all trailing spaces.
Supported
Supported
Returns a LineStringinstance (which is the distance between the two geometry instances) with two points that represent the shortest distance between the two geometry instances.
Supported
In Progress
Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.
Supported
Supported
Returns the trigonometric sine of the specified angle, in radians, and in an approximate numeric, float, expression.
Supported
Supported
Returns a smalldatetime value for the specified date and time
Supported
In Progress
Returns a four-character (SOUNDEX) code to evaluate the similarity of two strings.
Supported
In Progress
Returns a string of repeated spaces.
Supported
In Progress
Returns the square of the specified float value.
Supported
Supported
Returns the square root of the specified float value.
Supported
Supported
Returns the total surface area of a geometry/geography instance.
Supported
In Progress
Returns the Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation of a geometry/geography instance.
Supported
In Progress
Returns the Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation of a geometry/geography instance.
Supported
In Progress
Returns the boundary of a geometry instance.
Supported
In Progress
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.
Supported
In Progress
Returns the geometry/geography center of a geometry/geography instance that consists of one or more polygons.
Supported
In Progress
Returns 1 if a geometry instance completely contains another geometry instance, returns 0 if it does not.
Supported
In Progress
Returns an object representing the convex hull of a geometry instance.
Supported
In Progress
Returns 1 if a geometry instance crosses another geometry instance. Returns 0 if it does not.
Supported
In Progress
Returns a polygonal approximation of a geometry instance that contains circular arc segments.
Supported
In Progress
Returns an object that represents the point set from one geometry instance that does not lie within another geometry instance.
Supported
In Progress
Returns 1 if a geometry instance is spatially disjoint from another geometry instance, returns 0 if it is not.
Supported
In Progress
Returns the shortest distance between a point in a geometry/geography instance and a point in another geometry/geography instance.
Supported
In Progress
Returns the end point of a geometry instance.
Supported
In Progress
Returns the minimum axis-aligned bounding rectangle of the instance.
Supported
In Progress
Returns 1 if a geometry instance represents the same point set as another geometry instance, returns 0 if it does not.
Supported
In Progress
Returns the exterior ring of a geometry instance that is a Polygon.
Supported
In Progress
Returns a specified geometry in a geometry collection.
Supported
In Progress
Returns the Open Geospatial Consortium (OGC) type name represented by geometry instance.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, it returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, it returns a geometry/geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Returns a geometry/geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
Supported
In Progress
Returns the specified interior ring of a Polygon geometry instance.
Supported
In Progress
Returns an object that represents the points where a geometry/geography instance intersects another geometry/geography instance.
Supported
In Progress
Returns 1 if a geometry instance intersects another geometry instance. Returns 0 if it does not.
Supported
In Progress
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.
Supported
In Progress
Returns 1 if a geometry instance is empty. Returns 0 if a geometry instance is not empty.
Supported
In Progress
Returns 1 if a geometry instance fulfills certain requirements.
Supported
In Progress
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.
Supported
In Progress
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.
Supported
In Progress
Returns the total length of the elements in a geometry/geography instance or the geometry/geography instances within a GeometryCollection.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Returns a geometry LineStringinstance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Returns the number of curves in a one-dimensional geometry instance.
Supported
In Progress
Returns the number of geometries that comprise a geometry instance.
Supported
In Progress
Returns the number of interior rings of a Polygon geometry instance.
Supported
In Progress
Returns the sum of the number of points in each of the figures in a geometry instance.
Supported
In Progress
Returns 1 if a geometry instance overlaps another geometry instance. Returns 0 if it does not.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Returns a geometry Point instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
Supported
In Progress
Returns a specified point in a geometry instance.
Supported
In Progress
Returns an arbitrary point located within the interior of a geometry instance.
Supported
In Progress
Augmented with any Z (elevation) and M (measure) values carried by the instance, returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
Supported
In Progress
Returns character data converted from numeric data.
Supported
In Progress
Returns 1 if a geometry instance is related to another geometry instance, otherwise, returns 0.
Supported
In Progress
Returns the start point of a geometry instance.
Supported
In Progress
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.
Supported
In Progress
Returns 1 if a geometry instance spatially touches another geometry instance. Returns 0 if it does not.
Supported
In Progress
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.
Supported
In Progress
Returns an object that represents the union of a geometry instance with another geometry instance.
Supported
In Progress
Returns 1 if a geometry instance is completely within another geometry instance; otherwise, returns 0.
Supported
In Progress
Returns part of a character, binary, text, or image expression in SQL Server.
Supported
Supported
Returns a datetimeoffset value that is changed from the stored time zone offset to a specified new time zone offset.
Supported
In Progress
Returns a datetime2(7) value that contains the date and time of the computer on which the instance is running.
Supported
In Progress
Returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance is running. The time zone offset is included.
Supported
In Progress
Returns a datetime2 value that contains the date and time of the computer on which the instance is running. The date and time are returned as UTC time (Coordinated Universal Time).
Supported
In Progress
TAN
Returns the tangent of the input expression.
Supported
Supported
Returns a time value for the specified time and with the specified precision.
Supported
In Progress
Returns a datetimeoffset value that is translated from a datetime2 expression.
Supported
In Progress
Returns a character expression with lowercase character data converted to uppercase.
Supported
Supported
Returns an integer that represents the year of the specified date.
Supported
In Progress
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
datepart |
year |
quarter |
month |
dayofyear |
day |
week |
weekday |
hour |
minute |
second |
millisecond |
microsecond |
nanosecond |
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 |
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 |
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 |
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:
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
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:
Cinchy Supported Functions covers the following topics:
Scalar Functions
Cinchy Functions and Cinchy User Defined Functions (UDFs) are used in conjunction with Cinchy DML and DDL 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.
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, each column in your query will need a Full Text Index.
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 order to return the synonymous forms, you must have a Thesaurus file configured. Find more information here.
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 order to use FREETEXT, you must have a Thesaurus file configured. Find more information here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
The set of functions listed in this page are for use in Cinchy's Connections Experience 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.
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:
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:
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
You can review the full list of in-progress function translations here.
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.
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:
Argument | Description |
---|---|
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 .
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
Parameter
The parameter value that you want to escape in order to be safe to use inside a URL without breaking it
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
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
A JSON path that specifies the property to extract. If the format of path isn't valid, JSON_VALUE returns an error.
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
A JSON path 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.
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
A JSON path that specifies the property to extract. It takes the following format:
[append] [ lax | strict ] $.<json path>
append Optional modifier that specifies that the new value should be appended to the array referenced by <json path>.
lax Specifies that the property referenced by <json path> does not have to exist. If the property is not present, JSON_MODIFY tries to insert the new value on the specified path. Insertion may fail if the property can't be inserted on the path. If you don't specify lax or strict, lax is the default mode.
strict Specifies that the property referenced by <json path> must be in the JSON expression. If the property is not present, JSON_MODIFY returns an error.
<json path> Specifies the path for the property to update. For more info, see JSON Path Expressions (SQL Server). JSON_MODIFY returns an error if the format of path isn't valid.
newValue
The new value for the property specified by path. The new value must be a [n]varchar or text.
ABS
COS
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:
SELECT ROUND(CAST (748.58 AS decimal (6,2)),-3);
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 JSON document without breaking it