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 group into two (2) categories:
Data Manipulation Language (DML) - Use DML to add, retrieve, update and manipulate data. For example, insert, update, delete.
Data Definition Language (DDL) - Use DDL 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:
Use Data Manipulation Language (DML) to add, retrieve, update and manipulate data. The Cinchy DML statements covered on this page are:
Use the SELECT
statement 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.
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).
Use an INSERT statement 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.
The table name requires the domain prefix.
Use the UPDATE statement to change the data in a table. The UPDATE statement modifies zero or more rows of a table, depending on how many rows meet the search condition specified in the WHERE clause. You can also use an UPDATE
statement to specify the values to be updated in a single row. To do this, specify the constants, host variables, expressions, DEFAULT, or NULL. Specify NULL to remove a value from a row's column (without removing the row).
The table name requires the domain prefix.
Use the DELETE statement to remove entire rows from a table. The number of rows deleted depends on how many rows match the search condition specified in the WHERE statement.
The table name requires the domain prefix.
Use the IF statement to execute a condition. If the condition is satisfied, then the Boolean expressions returns TRUE value. The optional ELSE keyword introduces another statement that executes when the IF condition isn't satisfied and returns FALSE value.
Use the DECLARE statement to declare a variable.
Use the SET
variable to assign a value to a variable.
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.
This page provides some examples of Cinchy Query Language in action.
This section breaks down some example queries for you to get a feel for the power of Cinchy Query Language (CQL) and how to use it. These simple examples provide a point of reference for you to create more complex queries.
For more information on saved queries, see our Builder Guide.
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. This example only includes entries where the [Name] isn't 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 the query pulls the 'Name' column from the [Tables] table, in the [Cinchy] Domain. There's also 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. There's also an optional ORDER BY clause, to order results based on the input values.
This example has a table with a view for My Open Tasks. This view uses currentuserID=(), which only shows the tasks assigned to the user currently logged in.
The below query finds the creator of any specific table, based on its tablecinchyid
. The query pulls 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 you run this query, where you can insert the Table ID number of the table you are curious about.
The example below uses a query to return a list of all tables created by a specific user. It pulls 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.
You can use If/Else statements in CQL to specify conditions. The example below uses a query to vote for user awards, and uses IF statements to look 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!"
The 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 triggers 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've added an option WHERE clause to ignore any data from the 'Sandbox' Domain.
This page will help you to understand the fundamentals of getting started with Cinchy Query Language.
Cinchy Query Language (CQL) is a specialized query language designed for managing and retrieving data and metadata across multiple tables in your network, consolidating it into single, actionable outputs. With CQL, you can:
Use the query editor for tasks like data retrieval or modification.
Work with table views.
Manage table indexes.
For a comprehensive list, see the CQL functions master list. for details.
All CQL queries are secured by default through universal data access controls. This ensures you only access data you're authorized to see.
CQL, unique to Cinchy, shares similarities with SQL and PGSQL but has key differences. The list below defines the foundational elements of CQL.
Cinchy's Query Builder UI pre-fills basic syntax to speed up your query process. You can add terms manually or drag onto the Query Builder. More details can be found on the Saved Queries page.
Queries generated by the Query Builder automatically exclude deleted data with a "WHERE [Deleted] IS NULL" clause. Remove the clause to include deleted records.
Always use the "[Domain].[Table]" format when querying tables. For instance, querying the Product Content Backlog table would follow the [Product].[Product Content Backlog] syntax.
For linked columns, employ the "[Column Name].[Linked Column Name]" format.
Example: To extract [Full Name] from the Users table through a linked column Requester, use [Requester].[Full Name].
You can access nested linked columns using extended syntax, like [Column Name].[Linked Column Name].[Linked Column Name]. For example, if you wanted to see the Manager ID of a specific employee, use [Employee].[Reports To].[Employee ID] to find the employee, who they report to, and their ID number.
For text or string data, encapsulate the text with single quotes, as in [Domain] = 'Sandbox'.
Use != to specify Not equal to. For example, [Domain] != 'Sandbox'.
Query draft rows using Draft([Column Name]). Also include [Column Name] for non-draft rows.
Default sorting is ascending unless specified.
In Boolean queries, 1 means true, 0 means false.
In Cinchy, version history labeling diverges from standard SQL systems. While typical systems use a single label like "version 1.2.4," Cinchy breaks this into two components: Version and Draft Data. These serve as ORDER BY options. For example, if Version is 2
and Draft Data is 5
, the complete version is denoted as 2.5
.
Errors will show in the Query Builder’s results pane.
For INSERT INTO, ensure column and value order matches.
A * after SELECT returns system columns for each entry.
Use RESOLVELINK for linked column values. Syntax: ResolveLink('value(s)','column in target table').
You can specify what your results return as in the Query Builder
The table below lists what your results can return:
The following tables show the data types 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:
Number | Text | Date |
---|---|---|
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 data type the column can hold (such as varchar, char, int, date).
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 has rows and columns, taken from fields of an original table and presents them with a different structure and organization. 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, including indexed views. ALTER VIEW doesn't affect dependent stored procedures or triggers and doesn't change permissions.
Syntax
Example
Use the DROP VIEW command to delete a view.
Syntax
Example
The CREATE INDEX statement is used to create indexes in tables.
Syntax
Example
The DROP INDEX statement is used to delete an index on a table.
Syntax
Example
Query return result | Description |
---|---|
Number | Text | Date |
---|---|---|
Binary | Text |
---|---|
Binary | Yes/No |
---|---|
Query Result (Approved Data Only)
Default return type. Returns table data that's approved. Ideal for use with external APIs.
Query Result (Including Draft Data)
Displays records, including those that are pending approval.
Query Result (Including Version History)
Returns a table from a SELECT query (including draft data) with historical data for all tables, as seen in the Collaboration Log, including all changes within the scope of the query.
Number of Rows Affected
Returns a single string response of the number of rows affected if the last statement is an INSERT, UPDATE, or DELETE.
Execute DDL Script
For queries with DDL (Data Definition Language) commands like CREATE, ALTER, DROP.
Single Value
Returns a result of 1 row x 1 column, irrespective of the underlying result set.
### Data return types
Int
NVarChar
DateTime
BigInt
VarChar
Date
Decimal
Char
Float
NChar
Money
NText
Numeric
Text
Real
SmallInt
SmallMoney
TinyInt
VarBinary
Bit
Int
NVarChar
DateTime
BigInt
VarChar
Date
Decimal
Char
Float
NChar
Money
NText
Numeric
Text
Real
SmallInt
SmallMoney
TinyInt
VarBinary
Bit
The Cinchy system values covered in this section:
The @cinchy_row_id function returns the cinchy ID of the last-inserted row.
Similar to the SQL construct of table-valued functions, you can SELECT
or CROSS JOIN
from a Cinchy UDF as if it's 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, you need to create a data table in the same format as the default Cinchy JSON Saved Query response (Image 1).
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:
CAST
This function is used with CONVERT to convert an expression of one data type to another.
This function isn't 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
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 isn't 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
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 Cinchy functions covered in this section are:
Use the resolveLink function to insert or update values for link columns. Use it with values in the target table or 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. This function has two optional parameters: CacheTimeout and RecordLimitForReturn.
To add a CacheTimeout, enter 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's 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 queries 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)"
In this example, we want to query all data in the Employees table, including the data that's pending a change request (Image 1).
To return results that include the draft changes in the First Name column, set your query results to Include Draft Data, and use the following syntax (Image 2):
Similar to the SQL construct of scalar-valued functions, you can use Scalar-valued functions 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 doesn't require a parameter. You can pass a string:
SELECT my_scalar('a') FROM [Cinchy].[Tables] WHERE [Deleted] IS NULL AND [Cinchy Id]=1
Once you confirm 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 (such as creating a row in another table), it should be a cached calculated column.
Watch out for the following scenarios:
Don't trigger when you don't have all the necessary fields.
Don't trigger when non-relevant data on the row changes.
Make sure to appropriately insert and/or update in another table.
Cinchy User Defined Functions (UDFs) give customers a way to specify and use more particular logic in your solutions than basic CQL. You can use CQL to simplify calculations and orchestrate automation to accommodate your business requirements.
UDFs are written in JavaScript.
Cinchy UDFs divide into two groups:
Table-Valued Functions - Similar to the SQL construct of table-valued functions, you can SELECT
or CROSS JOIN
from a Cinchy UDF as if it's 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, try pasting it into JSHint, a tool that helps to detect errors and potential problems in your JavaScript code, as it also runs ECMAScript 5.1.
All UDFs are registered in the Cinchy User Defined Functions table (Image 1).
Don't name UDFs the same names as SQL or CQL functions. Doing so may cause your platform to break. For example, don't name your UDF CONCAT.
All Cinchy UDFs use JavaScript, and follow the convention below:
UDFs can perform external API calls and execute Cinchy Queries. All UDFs should return an indication of success or failure, even if you don't want to return any values.
You can create helper functions within a UDF, but you can't reference other UDFs.
To use advanced functions in UDFs, import the following:
You can use the following functions in a Cinchy UDF (but not in CQL directly).
You can use XMLHttpRequest()
helper to help POST or GET data from an external API. You can also access Cinchy basicAuthAPIs this way.
You can execute a Cinchy query or a non query (not expecting a result back) in a UDF.
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:
Date and Time Function Categories
Data type | Format | Range | Accuracy | Storage size (bytes) | User-defined fractional second precision | Time zone offset |
---|
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 isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
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.
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.
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.
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.
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.
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 isn't 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 aren't 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.
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.
The following example demonstrates the use of the fractions and precision parameters:
When fractions have a value of 5 and precision has a value of 1, then the value of fractions represents 5/10 of a second.
When fractions have a value of 50 and precision has a value of 2, then the value of fractions represents 50/100 of a second.
When fractions have a value of 500 and precision has a value of 3, then the value of fractions represents 500/1000 of a second.
SQL derives all system date and time values from the operating system of the computer on which the instance of SQL Server runs.
SQL Server 2019 (15.x) derives the date and time values through use of the GetSystemTimeAsFileTime() Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of SQL Server running. This API has a precision fixed at 100 nanoseconds. Use the GetSystemTimeAdjustment() Windows API to determine the accuracy. The return system date and time value functions covered in this section are:
SYSDATETIME returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
SQL statements can refer to SYSDATETIME
anywhere they can refer to a datetime2(7) expression.
SYSDATETIME
is a nondeterministic function. You can't index views and expressions that reference this function.
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.
SQL statements can refer to SYSDATETIMEOFFSET
anywhere they can refer to a datetimeoffset expression.
SYSDATETIMEOFFSET
is a nondeterministic function. You can't index views and expressions that reference this function.
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. You can't index views and expressions that reference this function.
The return date and time difference value functions covered in this section are:
The DATDIFF
function returns the count of the specified datepart boundaries crossed between the specified startdate and enddate.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
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 can't 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
doesn't 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's 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.
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
doesn't 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's out of range for BigInt.
This example uses different types of expressions as arguments for the startdate and enddate parameters. It calculates the number of day boundaries crossed between dates in two columns of a table.
The modify date and time value functions covered in this section are:
DATEADD function adds a specified number value to a specified datepart of an input date value, and then returns that modified value.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
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 won't 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.
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 can't 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's changed from the stored time zone offset to a specified new time zone offset.
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's different from the time zone offset that was originally stored. SWITCHOFFSET doesn't 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's translated from a datetime2 expression.
### Syntax
expression
Is an expression that resolves to a datetime2 value.
time_zone
Is an expression that represents the time zone offset in minutes (if an integer), for example -120, or hours and minutes (if a string), for example '+13:00'. The range is +14 to —14 (in hours). The expression is interpreted in local time for the specified time_zone.
datetimeoffset. The fractional precision is the same as the datetime argument.
Changing the time zone offset of the current date and time
The following example changes the zone offset of the current date and time to time zone -07:00
.
Changing the time zone offset in minutes
The following example changes the current time zone to -120
minutes.
Adding a 13-hour time zone offset
The following example adds a 13-hour time zone offset to a date and time.
The return date and time part functions covered in this section are:
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
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
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 doesn't 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.
This example returns the Base Year.
This example returns the Day part of the Date.
This example returns the Year part of the Date.
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.
This returns 30
- the number of the day itself
This statement returns 1900, 1, 1
. The date argument has a number value of 0
. SQL Server interprets 0
as January 1, 1900.
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.
The following statement returns 4
. This is the number of the month.
The following statement returns 1900, 1, 1
. The argument for date is the number 0
. SQL Server interprets 0
as January 1, 1900.
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.
With Cinchy, you can now create spatial tables with geometry and geography data sets, and blend this with other sources to unlock more intelligence from your fabric.
You can use this data 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 divide into the following pages:
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 isn't 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.
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 isn't 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.
boolean_expression
A valid Boolean expression.
If this argument isn't 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. The true_value is returned if the Boolean expression is TRUE, and the false_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 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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
integer_expression
An integer from 0 through 255.
char(1)
This function searches for one character expression inside another character string. If found, the function will return the starting position of the first expression.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
expressionToFind
The expression that needs to be found in the ExpressionString
expressionString
The string that contains the expression
start_Location
Start location from where the search will start
If CHARINDEX doesn't 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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
An alphanumeric expression of character data. string can be a constant, variable, or column.
int
Returns a value formatted with the specified format. Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general data type conversions, use CAST or CONVERT.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
value
Expression of a supported data type to format. For a list of valid types, see the table in the following Remarks section.
format
nvarchar format pattern.
The format argument must contain a valid .NET Framework format string, either as a standard format string (for example, "C" or "D"), or as a pattern of custom characters for dates and numeric values (for example, "MMMM DD, YYYY (DDDD)").
nvarchar or null
The length of the return value is determined by the format.
The following table lists the acceptable data types for the value argument together with their .NET Framework mapping equivalent types.
FORMAT with strings
The following example shows formatting date values by specifying a custom format.
FORMAT with numeric values.
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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
Is the string expression.
bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise, int.
The following example selects the number of characters and the data in string abcde
.
Returns a character expression after converting uppercase character data to lowercase.
string
Is an expression of character or binary data.
varchar or nvarchar
The following example uses the LOWER
function.
Returns a character expression after it removes leading blanks.
string
Is an expression of character or binary data.
varchar or nvarchar
Example: Using LTRIM
The following example uses LTRIM to remove leading spaces from a string
Returns the starting position of the first occurrence of a pattern in a specified expression.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
pattern
Is a character expression that contains the sequence to be found. Wildcard characters can be used; however, the % character must come before and follow pattern.
expression
Is an expression, typically a column that's 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's 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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
Is an alphanumeric expression of character data. SOUNDEX converts an alphanumeric string to a four-character code that's 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
, aren't included.
Returns a string of repeated spaces.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
integer_expression
Is a positive integer that indicates the number of spaces.
varchar
The following example concatenates a comma, two spaces, and the first name of the person.
Returns character data converted from numeric data. The character data is right-justified, with a specified length and decimal precision.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
float_expression
Is an expression of approximate numeric (float) data type with a decimal point.
length
Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.
decimal
Is the number of places to the right of the decimal point. decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point.
varchar
The following example converts an expression that's 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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
string
Is an expression of character data.
start
Is an integer value that specifies the location to start deletion and insertion.
length
Is an integer that specifies the number of characters to delete.
replaceWith
Is an expression of character data.
Returns character data if string is one of the supported character data types. Returns binary data if string is one of the supported binary data types.
The following example returns a character string created by deleting three characters from the first string, abcdef
, starting at position 2
, at b
, and inserting the second string at the deletion point.
Returns part of a character, binary, text, or image expression in SQL Server.
expression
Is a character, binary, text, ntext, or image expression.
start
Is an integer or bigint expression that specifies where the returned characters start.
length
Is a positive integer or bigint expression that specifies how many characters of the expression will be returned.
Returns character data if expression is one of the supported character data types. Returns binary data if expression is one of the supported binary data types. The returned string is the same type as the specified expression with the exceptions shown in the table.
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.
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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
base
Optional integer argument that sets the base for the logarithm.
Applies to: SQL Server 2012 (11.x) and later
float
By default, LOG() returns the natural logarithm. Starting with SQL Server 2012 (11.x), you can change the base of the logarithm to another value by using the optional base parameter.
The natural logarithm is the logarithm to the base e, where e is an irrational constant approximately equal to 2.718281828.
The natural logarithm of the exponential of a number is the number itself: LOG( EXP( n ) ) = n. And the exponential of the natural logarithm of a number is the number itself: EXP( LOG( n ) ) = n.
The following example calculates the LOG
for a specified number.
Returns the base-10 logarithm of the specified float expression.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
float
The LOG10 and POWER functions are inversely related to one another. For example, 10 ^ LOG10(n) = n.
Calculating the base 10 logarithm for a variable.
The following example calculates the LOG10
of the specified number.
Calculating the result of raising a base-10 logarithm to a specified power.
The following example returns the result of raising a base-10 logarithm to a specified power.
Returns the constant value of PI.
float
The following example returns the value of PI
.
Returns the value of the specified expression to the specified power.
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
y
Is the power to which to raise float_expression. y can be an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
The return type depends on the input type of float_expression:
If the result doesn't 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 isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
Returns the same type as numeric_expression.
The following example shows the number of radians based on a specified degree.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform.
New function translations are actively being worked on by the development team; please check back at a later time.
Returns a pseudo-random float value from 0 through 1, exclusive.
seed
Is an integer expression (tinyint, smallint, or int) that gives the seed value. If seed isn't 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.
All functions that have Geometry in parenthesis are only applicable to OGC methods on geometry instances.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
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 won't 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 can't 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 isn't 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. Otherwise, returns 0.
other_instance
Another geometry instance to compare against the instance on which STContains()
is invoked.
CQL: Yes/No
If the spatial reference identifiers (SRIDs) of the geometry instances don't 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. Otherwise, returns 0.
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 don't 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 isn't 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 doesn't 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 don't 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. Otherwise, returns 0.
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 disjoint.
Returns null if the spatial reference IDs (SRIDs) of the geometry instances don't 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 don't 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. Otherwise, returns 0.
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 don't match.
STExteriorRing()
returns the exterior ring of a geometry instance that's a Polygon
.
CQL: geometry
Returns null if the geometry instance isn't 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's 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's 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 isn't 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.
instance_tagged_text
An nvarchar(max) expression that's 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's 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 isn't 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 don't 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. Otherwise, returns 0.
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 don't 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 isn't 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 isn't 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's a LineString
instance.
It's closed (for a geometry to be closed, STIsClosed() needs to return 1 when invoked on the instance).
It's simple (for a geometry to be simple, STIsSimple() needs to return 1 when invoked on the instance).
Returns 0 if the LineString
instance doesn't meet the requirements.
CQL: Yes/No
Returns null if the instance isn't 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 isn't 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's 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 isn't 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's 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's 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's 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's 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's 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 isn't 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 doesn't 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 isn't 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 isn't 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. Otherwise, returns 0.
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 aren't in the same dimension, STOverlaps()
always returns 0.
If the spatial reference IDs (SRIDs) of the geometry instances don't 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 doesn't equal either instance.
This example uses STOverlaps()
to test two geometry instances for overlap:
Only available in SQL Server 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's 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's 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 SQL Server 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's 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 don't match, method returns null.
If matrix isn't 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 don't 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 doesn't.
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're touching but their interiors don't intersect.
If the spatial reference IDs (SRIDs) of the geometry instances don't 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 don't 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 don't 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:
Without century | With century | Input/Output | Standard |
---|---|---|---|
Value | Explanation |
---|---|
Value | Explanation |
---|---|
Value | Definiton |
---|---|
Column Name | Description |
---|---|
Method | Description |
---|---|
Method | Description |
---|---|
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
You can review the full list of in-progress function translations.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see .
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.
Category | Type | .NET type |
---|
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
Input type | Return type |
---|
You can review the full list of in-progress function translations
You can review the full list of in-progress function translations
Expression result | Return type |
---|
Examples | Results |
---|
Examples | Results |
---|
Specified expression | Return type |
---|
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 .
Name
The Name column contains the name of the User Defined Function.
Script
The Script column can contain any number of JavaScript functions that are necessary and referenced by the single function that's 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.
execute
This returns a queryResult
object that has additional information about your query. The final parameter in execute determines whether it's a query or non query. true = queryfalse
= non query. For more information, see the queryResult example below.
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
#### Converting float to real
0
Maximum 6 digits (default)
1
8 digits
2
16 digits
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
Function Name
GetLastModifiedBy
Function Description
This function will return the CinchyID of the user who last modified the specified column.
Function Type
Scalar
Return Type
Numeric. It returns the CinchyID
datepart name |
year |
quarter |
month |
dayofyear |
day |
week |
hour |
minute |
second |
millisecond |
microsecond |
nanosecond |
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 |
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 |
float, real | float |
decimal(p, s) | decimal(38, s) |
int, mallint, tinyint | int |
bigint | bigint |
money, smallmoney | money |
bit, char, nchar, varchar, nvarchar | float |
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 |
ROUND(748.58, -4) | 0 |
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 can't return 1000.00. |
To round up to 4 digits, change the data type of the input. For example:
| 1000.00 |
bigint | bigint |
int/smallint/tinyint | int |
money/smallmoney | money |
numeric/decimal | numeric/decimal |
Other types | float |
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 |
hour |
minute |
second |
millisecond |
microsecond |
nanosecond |
datepart |
year |
quarter |
month |
dayofyear |
day |
week |
weekday |
hour |
minute |
second |
millisecond |
microsecond |
nanosecond |
datepart |
year |
quarter |
month |
dayofyear |
day |
week |
weekday |
hour |
minute |
second |
millisecond |
microsecond |
nanosecond |
TZoffset |
ISO_WEEK |
The validate date and time value function covered in this section is:
ISDATE checks an expression to see if it's 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 isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see the CQL functions reference page.
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, aren't 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 isn't equal to 0, 100, 9, or 109.
The return value of ISDATE
depends on the settings set by SET DATEFORMAT
, SET LANGUAGE
and Configure the default language Server Configuration Option.
Using ISDATE to Test Valid datetime Expression
| | | |
| | |
| | |
|
The set of functions listed in this page are for use in the Cinchy Connections Experience when configuring data syncs.
Use @COLUMN for dynamic column referencing in data syncs, specifically for mapping Cinchy sources to REST or SOAP destinations.
The following snippet links the @COLUMN
mapped to Name
to employeeName
.
The following example uses a Cinchy Table as a Source with a REST API destination.
This scenario will map data from a table called Employees that contain two columns: Name
and EmployeeID
. We will map the Name
property in a Cinchy Table to the REST API destination property employeeName
.
In the Source tab, set the source to Cinchy Table.
In the Schema section, define your columns for Name
and Id
:
Id
, with a Data Type of Number.
Name
with a Data Type of Text.
In the Destination tab, go to REST API > API Specification > Insert Specification > Request and select POST with an endpoint URL.
Enter the mapping into the Body. Use @COLUMN
, then append the name to link it to the Name
column of the Cinchy Table, as shown in the sample below:
This function escapes reserved or special characters in parameter values in a JSON document, making it possible to insert them into strings.
Use this function in any REST API connection that accepts parameters, such as URL endpoints, Request Body, or Post-Sync Scripts.
The following example shows how you would use JSON_ESCAPE in your REST API URL (Image 1).
This example uses an API and adds a value (@Parameter) that contains double quotes -- this could break the JSON structure, so you 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).
This example uses an API and adds a value (@Parameter) that contains double quotes -- this could break the JSON structure, so you need to wrap the parameter with JSON_ESCAPE().
Use this function in Connections to escape parameter values for 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).
This example uses an API and adds a value (@Parameter) that contains the "&" symbol to the URL field. To properly read the URL, you need to wrap the parameter with URL_ESCAPE(), which will escape the & to be %26.
The STRING_ESCAPE() function escapes single quotes in data sync parameters by adding two single quotes. It can be used to wrap around parameters or column references respectively. This can be useful when you use it in a post sync script's CQL.
Or
Or, when used inside of a post sync script or the sync body:
The example below uses a string escape for the last name to catch any single quotes, such as O'Connell
.
The @ID
function is specific to full file syncs. One of its primary uses in data syncs where the source is Cinchy Event Broker and the destination is a REST API to reconcile specific properties.
The following example uses the Cinchy Event Broker as a Source with a REST API destination.
This scenario updates the data from the employeeID
property to the source. The example below is a REST API response from our destination.
Under REST API SOURCE, configure your endpoint to the URL of the API request. For this example, your response format would be JSON, your Records Root JSONPath is $.data
, and your ID Column is $.employeeID
.
With this configuration, your @ID
is now mapped to the data.employeeID
in your JSON file.
Under REST API > API Specification > Update Specification > Body, the following content maps the id
property to the @ID
function:
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.
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.
Cinchy has 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 *
at the end.
This example modifies the search so that you receive all results where the any word in the Title column has 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).
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.
That is, install might return results with deploy, configure, set.
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.
Proximity terms in Cinchy don't adhere to the specified order written in the query. You will receive results of both term 1+term 2 and 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 (like 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's therefore a better option if you are searching phrases, in lieu of individual words.
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.
For example, installation guide might return results with deployment instructions, set up guide.
This page details the available JSON functions in Cinchy. The JSON functions covered in this section are:
These functions aren't currently available in PostGres deployments.
This function tests whether a string contains valid JSON.
Argument | Description |
---|---|
Return Value | Description |
---|---|
This example will return all rows from the [Expression] column in the [Product].[Function Table] that contain valid JSON.
This example would return a 1 since the expression ('true') is valid JSON.
This functions extracts a scalar value from a JSON string.
Returns a single text value of type nvarchar(4000). The collation of the returned value is the same as the collation of the input expression.
The following example extracts the value of the JSON property into a local variable.
This function extracts an object or an array from a JSON string.
Returns a JSON fragment of type nvarchar(max). The collation of the returned value is the same as the collation of the input expression.
It would return the following result:
This function updates the value of a property in a JSON string and returns the updated JSON string.
Returns the updated value of expression as properly formatted JSON text.
The following example sets the surname to Smith.
It would return the following formatted JSON text:
Cinchy CQL supports several extended methods on Open Geospatial Consortium (OGC) methods on geometry and geography instances.
All functions that have Geometry in parenthesis are only applicable to OGC methods on geometry instances.
This function isn't currently supported in PostgreSQL deployments of the Cinchy platform. Please check back at a later time. For a full list of in-progress function translations, see the CQL functions reference page.
The extended Methods covered in this section are:
IsValidDetailed()
returns a message that can help to identify problems with a spatial object that's not valid.
Only the first error is returned, when the object isn't 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.
Doesn't 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 isn't 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.
Returns an empty LineString
instance 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:
Argument | Description |
---|---|
Argument | Description |
---|---|
Argument | Description |
---|---|
Argument | Description |
---|---|
Return Value | Description |
---|---|
Expression
The string to test.
1
Returned if the input is a valid JSON object or array.
0
Returned if the input isn't 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's 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's 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's 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's 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
newValue
The new value for the property specified by path. The new value must be a [n]varchar or text.
Parameter
The parameter value that you want to escape for use inside a URL without breaking it
24400
Valid
24401
Not valid, reason unknown.
24402
Not valid because point {0} is an isolated point, which isn't 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} isn't 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 isn't 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} isn't 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