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

Incorrect results for negative intervals #6720

Closed
Tracked by #3148 ...
alamb opened this issue Jun 19, 2023 · 2 comments
Closed
Tracked by #3148 ...

Incorrect results for negative intervals #6720

alamb opened this issue Jun 19, 2023 · 2 comments

Comments

@alamb
Copy link
Contributor

alamb commented Jun 19, 2023

          To me this doesn't look right. The previous test seems correct. When putting a negation in front of interval I believe it should negate the entire interval statement.

interval '5' - '1' - '2' year is one interval statement.

I think the statement

select -interval '5' - '1' - '2' year;

Should be interpreted as:

select - (interval '5' - '1' - '2' year);

Rather than

select (- interval '5') - '1' - '2' year;

If the user wants to negate only 5, they should write it as follows (below are all equivalents):

select interval '-5' - '1' - '2' year;
select interval - '5' - '1' - '2' year;
select - interval '5' year - interval '1' year - interval '2' year;

Originally posted by @aprimadi in #6698 (comment)

@alamb
Copy link
Contributor Author

alamb commented Jun 19, 2023

However, note the current datafusion behavior is consistent with postgres as explained by @waitingkuo in #6698 (review):


looks good to me, thanks.

in postgrseql

select -interval '5' - '1' - '2';

is intepreted as

select (-interval '5') - '1' - '2';
willy=# select -interval '5' - '1' - '2';
 ?column?  
-----------
 -00:00:08
(1 row)

note that select -interval '5' - '1' - '2' hour doesn't work in postgresql

willy=# select -interval '5' - '1' - '2' hour;
ERROR:  syntax error at or near "hour"
LINE 1: select -interval '5' - '1' - '2' hour;

@alamb
Copy link
Contributor Author

alamb commented Sep 19, 2023

I don't think this ticket is tracking anything actionable now, so closing

@alamb alamb closed this as completed Sep 19, 2023
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

1 participant