How in plpgsql use LIKE with a variable?
let say I want to do this query:
SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1;
keyword is a variable, in this case I want to find name like 'Jo%'
====================================================
Full function:
CREATE OR REPLACE FUNCTION custlike(text) RETURNS INT4 AS'
DECLARE
keyword ALIAS FOR $1;
RS RECORD;
BEGIN
SELECT INTO RS id FROM customer WHERE firstname like keyword% LIMIT 1;
IF FOUND THEN
RETURN RS.id;
ELSE
RETURN NULL;
END IF;
END'
LANGUAGE 'PLPGSQL';