Vertica function with select clause
Hello guys!
I need help with setting up a function. My intention is to pass to this function a set of parameters that will compose a select and the function will return the result of the select. Is it possible to do this in Vertica?
Thank you.
1
Answers
Not at this time ... you can, though, code it as SQL generating SQL, and then call it:
A bit rough, but I do that all the time ...
note that the string parameter is a double quote, a single quote, then the string, then a single quote, then a double quote....
@mpedroso,
Can you please explain your use case a bit more? It seems like, you want to generate dynamic SELECT statement for performance improvement? I used to do that in traditional DB like Oracle, DB2, and SQL Servers all the time. However in Vertica it is NOT required. Though as suggested by marcothesane, this can be done from shell using scripting or python, this is really not required.
Please give us more on why you want to do this. May be we can help more.
Thx.
@all thanks for the replies you guys.
I am wanting to use a function in a select that queries a given history table and returns the value found in select.
Example:
select
*,
rescue_hist_charge (employee_code, date) lastcharge
from employees
Function:
var v1 int;
select cod_charge into v1 from hist_charge where employee_code = @ {employee_code} and start_date = @ {date}
return v1;
@mpedroso ,
From your code sample it seems, rescue_hist_charge function is a scalar function & returns a single value. Is that correct?
If so, you can just join employees and hist_charge table on employee_code and date columns.
For example:
Hope this helps.