Create Function issue in the Vertica
I want to create this function but facing issue
CREATE OR REPLACE FUNCTION RAW.getType(input_string VARCHAR)
RETURN VARCHAR AS
BEGIN
RETURN (
SELECT Type
FROM RAW.TYPE
WHERE LENGTH(input_string) = LENGTH
AND input_string LIKE PATTERN || '%'
LIMIT 1
);
END;
Gives Error as Column "input_string" does not exist
also tried with declare result
CREATE OR REPLACE FUNCTION RAW.getType(num VARCHAR)
RETURN VARCHAR
AS
BEGIN
DECLARE result VARCHAR;
SELECT Type INTO result FROM RAW.TYPE WHERE LENGTH(num) = LENGTH AND num LIKE PATTERN || '%' LIMIT 1; RETURN result;
END;
This gives the syntax error
Need to create function query for above select query
0
Answers
Vertica does not support using queries directly within User-defined SQL functions.
This is why you're encountering errors when trying to create a function with a SELECT statement inside it.
Instead of a SQL function, please consider a stored procedure (SP) approach as shown in the following example:
But procedure wont return value So I cant use it my Select query as functions?