Skip to content

feat: standard database functions everywhere #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions guides/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,12 @@ by deviating from the casing given below.
- `round(x)`
Rounds the numeric parameter to the nearest integer.
Copy link
Contributor

@agoerler agoerler Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • CAP Java: WIP: https://github.wdf.sap.corp/cds-java/cds4j/pull/3590
  • What's the return type? Type of x? Int32? Int64?
  • SQL also know round with two parameters where the second parameter which indicates the number of digits to round to. There are issues on SQLite with this second parameter. I assume there is no plan to support the method with two parameters.
  • On Postgres we observed that Postgres and Double elements rounds to the nearest even integer

https://www.postgresql.org/docs/16/functions-math.html

Rounds to nearest integer. For numeric, ties are broken by rounding away from zero. For double precision, the tie-breaking behavior is platform dependent, but “round to nearest even” is the most common rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java:

  • return type: Type of x.
  • available now

The midpoint between two integers is rounded away from zero (e.g., `0.5` → `1` and `-0.5` → `-1`).

::: warning `round` function with more than one argument
please note that most databases support `round` functions with multiple arguments.
The second parameter being the precision. SAP HANA even has a third argument which is the rounding mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that using a negative precision does not work on SQLite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only take care of the one argument variant of the round function, as we try to replicate the OData round. Everything else will be db-specific, which is what I tried to outline in this warning. @stewsk what do you think?

If you provide more than one argument, the `round` function may behave differently depending on the database.
:::

#### Date and Time Functions

Expand Down