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

Support automatic string --> interval casting #5652

Closed
Tracked by #5753
alamb opened this issue Mar 20, 2023 · 3 comments
Closed
Tracked by #5753

Support automatic string --> interval casting #5652

alamb opened this issue Mar 20, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@alamb
Copy link
Contributor

alamb commented Mar 20, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I would like to write a query like

select * from foo where x < now() - '1 day';

Here is what happens today

❯ create table foo(x timestamp) as select '2023-03-01'::timestamp;
0 rows in set. Query took 0.002 seconds.
❯ select * from foo;
+---------------------+
| x                   |
+---------------------+
| 2023-03-01T00:00:00 |
+---------------------+
1 row in set. Query took 0.001 seconds.
❯ select * from foo where x < now() - '1 day';
Internal error: The type of Timestamp(Nanosecond, Some("+00:00")) Minus Utf8 of binary physical should be same. This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker

Describe the solution you'd like
I would like the query to work (by adding coercion rules to automatically coerce string --> interval if appropriate)

Describe alternatives you've considered
N/A

Additional context
I think we will need to fix #5650 and #5651

@Dandandan
Copy link
Contributor

You can't do this in PostgreSQL too, without adding INTERVAL, like this:

select now() - interval '1 day';

@Dandandan
Copy link
Contributor

The same works today in datafusion:

❯ select now() - interval '1 day';
+------------------------------------------------------+
| now() - IntervalMonthDayNano("18446744073709551616") |
+------------------------------------------------------+
| 2023-06-07T13:58:37.973698Z                          |
+------------------------------------------------------+
1 row in set. Query took 0.003 seconds.

@Dandandan
Copy link
Contributor

This does work in postgresql though and not in datafusion:

select '1 day' - interval '1 hour';

@alamb alamb closed this as completed Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants