plpgsql.. SELECT INTO ... WHERE FIELD LIKE

From: "Yudie" <yudie(at)axiontech(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: plpgsql.. SELECT INTO ... WHERE FIELD LIKE
Date: 2004-12-16 23:53:43
Message-ID: 001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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';

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2004-12-17 00:46:17 Re: plpgsql.. SELECT INTO ... WHERE FIELD LIKE
Previous Message Marcus Krause 2004-12-16 21:23:23 get branches & childs from database