plpgsql.. SELECT INTO ... WHERE FIELD LIKE - Mailing list pgsql-sql

From Yudie
Subject plpgsql.. SELECT INTO ... WHERE FIELD LIKE
Date
Msg-id 001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com
Whole thread Raw
Responses Re: plpgsql.. SELECT INTO ... WHERE FIELD LIKE
List pgsql-sql
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';
 

pgsql-sql by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: [despammed] question about index
Next
From: Michael Fuhr
Date:
Subject: Re: plpgsql.. SELECT INTO ... WHERE FIELD LIKE