Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group