-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed as not planned
Description
Do we have any method to convert or cast the integer type/integer expr with the timeunit to the interval?
I want to implement a app or function like this datetime + integer with timeunit, and the timeunit may be year,month,day.
I can't find the any method to convert the integer with timeunit to the interval, but in the PG which has a function make_interval() https://www.postgresql.org/docs/current/functions-datetime.html can do this.
I just can find a way to resolve the issue by using the concat method.
For example: I have a table like below, and want to convert the b with dayunit to interval
❯ \d test
+---------------+--------------+------------+-------------+-----------+-------------+
| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |
+---------------+--------------+------------+-------------+-----------+-------------+
| datafusion | public | test | a | Date32 | NO |
| datafusion | public | test | b | Int64 | NO |
+---------------+--------------+------------+-------------+-----------+-------------+
2 rows in set. Query took 0.013 seconds.
Using the concat to get the utf8 expr which can be casted to interval.
❯ select cast(concat(b,' day') as interval), b from test;
+-------------------------------------------------------+---+
| concat(test.b,Utf8(" day")) | b |
+-------------------------------------------------------+---+
| 0 years 0 mons 2 days 0 hours 0 mins 0.000000000 secs | 2 |
+-------------------------------------------------------+---+
Originally posted by @liukun4515 in #3148 (comment)
Metadata
Metadata
Assignees
Labels
No labels