plpgsql

From: Jason Boxman <benefits(at)cybertechs(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: plpgsql
Date: 1999-03-09 19:28:08
Message-ID: 99030914324600.01334@nebula.egb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hey all!

I want to use a "LIKE" comparison in my plpgsql script, but I'm unsure how to
do it... What I have right now doesn't work as hoped (although I did expect it
to not work).

UPDATE dir SET udate = curtime WHERE ''bind_dir.dir''::text LIKE ''%mydir%''::text AND
dir.uid = bind_dir.uid;

The above comparison fails as Postgres interprets the variables bind_dir.dir
and mydir as text when enclosed in two single quotes... but I cannot just tag
the '%' percent sign along after 'mydir', or the function won't compile. So
how can I utilize the LIKE (or ~~) operator in my plpgsql scripts?

I can provide futher information (table dumps, scope of what the heck I'm
trying to do, ect. upon request, but this is probably just a silly oversight on
my part.)

If you could reply to me directly, I'd appreciate it as I'm not on the list
right now... Thanks!

-Full function-

create function bind_clean_bind () RETURNS OPAQUE AS '
DECLARE
bind_dir RECORD;
mydir dir.dir%TYPE;
curtime datetime;
BEGIN
IF TG_OP = ''UPDATE'' OR TG_OP = ''DELETE'' THEN
SELECT dir INTO mydir FROM dir WHERE uid = OLD.duid;
IF FOUND THEN
FOR bind_dir IN SELECT uid,dir FROM dir;
curtime := ''now'';
UPDATE dir SET udate = curtime WHERE ''bind_dir.dir''::text LIKE ''%mydir%''::text AND dir.uid = bind_dir.uid;
END LOOP;
END IF;
END IF;
IF TG_OP = ''UPDATE'' OR TG_OP = ''INSERT'' THEN
SELECT dir INTO mydir FROM dir WHERE uid = NEW.duid;
IF FOUND THEN
FOR bind_dir IN SELECT uid,dir FROM dir;
curtime := ''now'';
UPDATE dir SET udate = curtime WHERE ''bind_dir.dir''::text LIKE ''%mydir%''::text AND dir.uid = bind_dir.uid;
END LOOP;
END IF;
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

--

Sincerely,
Jason Boxman

http://edseek.com/ - Your source for educational excellence

"Two roads diverged in a wood, and I-- \ I took the one lessed
traveled by, \ And that has made all the difference."
-Robert Frost, "The Road Not Taken"

Browse pgsql-general by date

  From Date Subject
Next Message Michael Meskes 1999-03-09 19:30:57 Re: [INTERFACES] the last row in a table
Previous Message Dustin Sallings 1999-03-09 19:24:15 Re: [GENERAL] Re: [INTERFACES] the last row in a table