How to add dynamic interval from the column

Viewed 37

In Hive I need to add interval, taken from column:

SELECT CAST('2017-09-22 17:22:38' as timestamp) + 
INTERVAL T.a minute 
FROM ( SELECT 1 as a) as T;

I got this error:

cannot recognize input near 'interval' 'T' '.' in 
expression specification. 

All examples of using INTERVAL which I found are using the constant value after INTERVAL, but in my case this is dynamic value from the table.

1 Answers

You just need put the dynamic var inside brackets. Below code will work.

SELECT CAST('2017-09-22 17:22:38' as timestamp) + 
INTERVAL (T.a) minute 
FROM ( SELECT 1 as a) as T;
Related