The Vertica Forum recently got a makeover! Let us know what you think by filling out this short, anonymous survey.
Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!
declare a variable inside a function
Hi!
I need to cast input value into string and than use it within the interval option.
Can I declare a variable inside a function?
The use is for: "current_timestamp + interval to_char(input) minute"
the input is numeric.
0
Best Answer
-
Bryan_H Vertica Employee Administrator
You can CAST a string to an interval, e.g. SELECT CAST('30 sec' AS INTERVAL);
Try concatenating your string like this: SELECT current_timestamp + CAST(input||' minute' AS INTEVRAL);
Please see also: https://docs.vertica.com/12.0.x/en/sql-reference/data-types/datetime-data-types/interval/casting-with-intervals/0
Answers
Why would you need to do that?
I know three - all pretty intuitive - ways to add minutes to timestamps.
TIMESTAMPADD(<_date_part_>,<_counter_>,<_datetime_val_>)
function'00:3'
, as anINTERVAL
(by putting a pair of round parentheses around the concatenation operation - so it does not try to cast just the integer cast to VARCHAR, to INTERVAL)It does not figure with me why you should want to create a function for that ...
I got one more expression I like to use as well, it is to multiply your input by the interval 1 minute: