You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cds/cxl.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -340,7 +340,7 @@ that multiplies the two factors `price` and `quantity`.
340
340
</div>
341
341
342
342
343
-
CAP supports a set of [portable functions](../guides/databases/cql-to-sql.md#portable-functions) that can be used in all expressions. Those functions are passed through to the underlying database, allowing you to leverage the same functions for different databases, which greatly enhances portability.
343
+
CAP supports a set of [portable functions](../guides/databases/cap-level-dbs#portable-functions) that can be used in all expressions. Those functions are passed through to the underlying database, allowing you to leverage the same functions for different databases, which greatly enhances portability.
344
344
345
345
## ref (path expression) { #ref }
346
346
@@ -835,4 +835,3 @@ navigates along the `author` association of the `Books` entity only if the autho
Copy file name to clipboardExpand all lines: guides/databases/cap-level-dbs.md
+65-34Lines changed: 65 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,26 @@
1
-
# CDS Compilation to Database-Specific SQL
1
+
# CAP-Level Database Integration
2
2
3
3
CAP supports a number of portable functions and operators in CQL. The compiler automatically translates these to the best-possible database-specific native SQL equivalents. You can safely use these in CDS view definitions and runtime queries expressed in CQL.
4
4
{.abstract}
5
5
6
6
[[toc]]
7
7
8
8
9
-
## Operators
9
+
## Mocked Out of the Box
10
+
11
+
When using CAP's mocked out-of-the-box database integration, these functions and operators are supported in the in-memory SQLite database used for development and testing.
12
+
13
+
#### TODO:
14
+
15
+
- Mocked by in-memory SQLite or H2 databases
16
+
- With SAP HANA or PostgreSQL for production
17
+
- With a defined set of portable functions and operators
18
+
19
+
## Standard Operators
20
+
21
+
This chapter lists standardized operators supported by CAP, and guaranteed to work across all supported databases with feature parity. You can safely use these in CDS view definitions and runtime queries expressed in CQL. The compiler translates them to the best-possible database-specific native SQL equivalents.
22
+
23
+
### Standard SQL Operators
10
24
11
25
Most native SQL operators are supported in CQL as-is, like these from the SQL92 standard:
12
26
@@ -77,13 +91,15 @@ FROM Books;
77
91
The compiler translates this operator to the best-possible equivalent in the target database: `CASE WHEN ... THEN ... ELSE ... END` in standard SQL, or `IF(..., ..., ...)` in SAP HANA.
78
92
79
93
80
-
## Functions
94
+
## Standard Functions
81
95
82
-
### Portable Functions
96
+
The following sections list standardized string, numeric, data/time, and aggregate functions supported by CAP, and guaranteed to work across all supported databases with feature parity. You can safely use these in CDS view definitions and runtime queries expressed in CQL. The compiler translates them to the best-possible database-specific native SQL equivalents.
97
+
98
+
> [!important] Function names are case-sensitive
99
+
> The names for standardized functions must be written exactly as listed above. For example, `toUpper` is invalid, while `toupper` is valid. Differently cased names might also work if they match native functions of the specific database, but are not guaranteed to be portable -> always use the exact casing as listed.
83
100
84
-
Following are portable functions supported by CAP. You can safely use these in CDS view definitions and runtime queries expressed in CQL. The compiler translates them to the best-possible database-specific native SQL equivalents.
85
101
86
-
String functions:
102
+
### String Functions
87
103
88
104
-`concat(x,y,...)`
89
105
-`length(x)`
@@ -97,48 +113,63 @@ String functions:
97
113
-`substring(x,start, length)`
98
114
-`matchespattern(x,pattern)`
99
115
116
+
In addition, to `concat()`, CAP also supports the common `||` operator for string concatenation in CQL queries, same as in SQL queries. For example, these two queries are equivalent:
117
+
118
+
```sql
119
+
SELECT concat (firstName,'',lastName) as fullName from Authors;
120
+
```
121
+
```sql
122
+
SELECT firstName ||''|| lastName as fullName from Authors;
123
+
```
124
+
125
+
126
+
> [!important] Indexes and Substring Details
127
+
> The return value of `indexof()` as well as the `start` parameter in `substring()` are zero-based index values. If the substring is not found, `indexof()` returns `-1`. If the `start` index in `substring()` is negative, it is counted from the end of the string. If the `length` parameter is omitted, the substring to the end of the string is returned.
100
128
101
-
Numeric functions:
129
+
130
+
### Numeric Functions
102
131
103
132
-`ceil(x)`, `ceiling(x)`
104
133
-`floor(x)`
105
134
-`round(x)`
106
135
107
-
###### aggregate-functions
108
-
Aggregate functions:
136
+
> [!warning] Non-portable <code>round()</code> function with more than one argument
137
+
> Note that databases support `round()` functions with multiple arguments, the second parameter being the precision. If you use that option, the `round()` function may behave differently depending on the database.
138
+
139
+
140
+
### Date / Time Functions
141
+
142
+
-`date(x)` -> `yyyy-MM-dd` strings
143
+
-`time(x)` -> `HH:mm:ss` strings
144
+
<br/><br/>
145
+
-`year(x)` -> integer
146
+
-`month(x)` -> integer
147
+
-`day(x)` -> integer
148
+
-`hour(x)` -> integer
149
+
-`minute(x)` -> integer
150
+
-`second(x)` -> integer
151
+
<br/><br/>
152
+
-`years_between(x,y)` -> number
153
+
-`months_between(x,y)` -> number
154
+
-`days_between(x,y)` -> number
155
+
-`seconds_between(x,y)` -> number
156
+
157
+
> [!note] CAP Java support coming soon...
158
+
> The above `*_between` functions are currently only supported by CAP Node.js. \
159
+
> Support for CAP Java is planned for a future release.
160
+
161
+
162
+
### Aggregate Functions
109
163
110
164
-`avg(x)`, `average(x)`
111
165
-`min(x)`, `max(x)`
112
166
-`sum(x)`
113
167
-`count(x)`
114
168
<!-- - `countdistinct(x)` -->
115
169
116
-
Date / Time functions:
117
-
118
-
-`date(x)` -> `yyyy-MM-dd`
119
-
-`time(x)` -> `HH:mm:ss`
120
-
-`year(x)`
121
-
-`month(x)`
122
-
-`day(x)`
123
-
-`hour(x)`
124
-
-`minute(x)`
125
-
-`second(x)`
126
-
-`years_between(x,y)`
127
-
-`months_between(x,y)`
128
-
-`days_between(x,y)`
129
-
-`seconds_between(x,y)`
130
-
131
-
> [!important] Function names are case-sensitive
132
-
> The function names must be written exactly as listed above. For example, `toUpper` is invalid, while `toupper` is valid. Differently cased names might also work if they match native functions of the specific database, but are not guaranteed to be portable -> always use the exact casing as listed.
133
-
134
-
> [!important] Non-portable <code>round()</code> function with more than one argument
135
-
> Note that databases support `round()` functions with multiple arguments, the second parameter being the precision. If you use that option, the `round()` function may behave differently depending on the database.
136
-
137
-
> [!note] Indexes and Substring Details
138
-
> The return value of `indexof()` as well as the `start` parameter in `substring()` are zero-based index values. If the substring is not found, `indexof()` returns `-1`. If the `start` index in `substring()` is negative, it is counted from the end of the string. If the `length` parameter is omitted, the substring to the end of the string is returned.
139
170
140
171
141
-
###Native Functions
172
+
## Native Functions
142
173
143
174
In general, the CDS compiler doesn't 'understand' SQL functions but translates them to SQL _generically_ as long as they follow the standard call syntax of `fn(x,y,...)`. This allows to use all native database functions inside your CDS models, like this:
144
175
@@ -152,7 +183,7 @@ SELECT from Books {
152
183
> Using native functions like this makes your CDS models database-specific, and thus less portable. Therefore, prefer using the [portable functions](#portable-functions) listed above whenever possible.
153
184
154
185
155
-
###Window Functions
186
+
## Window Functions
156
187
157
188
[SQL window functions](https://en.wikipedia.org/wiki/Window_function_(SQL)) with `OVER` clauses are supported as well, for example:
Copy file name to clipboardExpand all lines: guides/databases/cdl-to-ddl.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -160,7 +160,7 @@ CREATE VIEW SomeProjection AS SELECT ... FROM SomeEntity;
160
160
:::
161
161
162
162
> [!tip] Views are defined using CQL
163
-
> Both view defined per `as projection on` and those using `as select from` are defined using CQL, which supports a broad scope of database-agnostic features. Learn more about that in the following guide: [_CQL Compilation to SQL_](cql-to-sql).
163
+
> Both view defined per `as projection on` and those using `as select from` are defined using CQL, which supports a broad scope of database-agnostic features. Learn more about that in the following guide: [_CQL Compilation to SQL_](cap-level-dbs).
Use [aggregation functions](../../guides/databases/cql-to-sql#aggregate-functions) to calculate minimums, maximums, totals, averages, and counts of values. You can use them in *columns* of `Select` statements to include the aggregated values in the result set, or in the [having](#having) clause to filter based on aggregated values.
716
+
Use [aggregation functions](../../guides/databases/cap-level-dbs#aggregate-functions) to calculate minimums, maximums, totals, averages, and counts of values. You can use them in *columns* of `Select` statements to include the aggregated values in the result set, or in the [having](#having) clause to filter based on aggregated values.
0 commit comments