I am new to postgreSQL database , can you explain me why i got syntax error ? I can't find any answer in documentation docs
CREATE OR REPLACE FUNCTION validation(string_to_match varchar [], pattern
varchar , validation_type varchar) RETURNS boolean AS $$
DECLARE a_length ALIAS FOR $1;
DECLARE result_validation ALIAS FOR $2;
BEGIN
CASE validation_type
WHEN 'login' THEN array_length (string_to_match , 1) INTO $1 RAISE NOTICE
'Array length is %', $1;
WHEN 'register' THEN array_length(string_to_match,1) INTO $1 RAISE NOTICE
'Array length is %', $1;
WHEN 'contact' THEN array_length(string_to_match,1) INTO $1 RAISE NOTICE
'Array length is %', $1;
END CASE;
END;
$$ lANGUAGE plpgsql;
ERROR: syntax error at or near "array_length" LINE 7: WHEN 'login' THEN array_length (string_to_match , 1) INTO... ^ SQL state: 42601 Character: 258
when validation_type = 'login' ...when validation_type = 'register' ...etcI'm not sure why but I've had this error before and that has worked as a work around.INTO $1makes no sense at the place where you put it. What exactly do you expect that to do? You are also missing areturnstatement. You have to explain to us what that function is supposed to do. As far as I can tell, the CASE is completely unnecessary as you simply output the (same) array length in all cases