Skip to content
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

Math operations with intervals #2377

Open
btqr opened this issue Jan 4, 2020 · 2 comments
Open

Math operations with intervals #2377

btqr opened this issue Jan 4, 2020 · 2 comments

Comments

@btqr
Copy link

btqr commented Jan 4, 2020

In version 1.4.197 I could run query like this:
select (DATE '2019-05-04' - DATE '2019-03-12' - 23);
and the output was number of days and that's also how it works on PostgreSQL database.

In the newest versions (1.4.198 and greater) when I run this query I get following answer:
Feature not supported: "INTERVAL DAY - INTEGER"

I know I can achieve same result with extract function, but it would require many changes in my application. Is it any workaround to upgrade the version of database and make this query works?

@katzyn
Copy link
Contributor

katzyn commented Jan 5, 2020

No, you can only change the sources of H2 by itself or change your queries.

Current behavior of H2 is correct here, the result of subtraction of two date values must be a daytime interval value. PostgreSQL violates the SQL Standard for the DATE data type only (it evaluates the subtraction between TIME or TIMESTAMP values correctly and returns a interval as expected). Old unsupported versions of H2 simply don't have the INTERVAL data type yet, so they also return an integer value for compatibility with some queries from Oracle.

@manticore-projects
Copy link
Contributor

I stumbled over this just by myself and solved it like that:

select Cast({d '2019-05-04'} - {d '2019-03-12'} AS DECIMAL) - 23 from dual;

Should be also Oracle and MSQL compatible.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants