pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Yudie <yudie@axiontech.com>
To: pgsql-sql@postgresql.org
Subject: plpgsql.. SELECT INTO ... WHERE FIELD LIKE
Date: Thu, 16 Dec 2004 17:53:43 -0600
Message-ID: <001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com> (raw)

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';

view thread (4+ messages)  latest in thread

Message-ID: <001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com>
Permalink:  ../001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com/
Also on:    postgresql.org/message-id/001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: yudie@axiontech.com
  Subject: Re: plpgsql.. SELECT INTO ... WHERE FIELD LIKE
  In-Reply-To: <001901c4e3ca$7c71aca0$a101a8c0@home.axiontech.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox