Re: Update function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Sharon Cowling" <sharon(dot)cowling(at)sslnz(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Update function
Date: 2001-11-01 04:37:17
Message-ID: 17329.1004589437@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Sharon Cowling" <sharon(dot)cowling(at)sslnz(dot)com> writes:
> I'm having trouble with a function

(a) returning NULL from a before-trigger is a signal to the system to
skip the insert (or update or delete). You need "return new" instead,
at least in the case where you want the insert to happen.

(b) this is pretty bizarre:

> IF new.my_code LIKE (SELECT my_code FROM permit WHERE my_code = new.my_code) THEN

Perhaps you meant

IF EXISTS(SELECT 1 FROM permit WHERE my_code = new.my_code) THEN

(c) this will have a syntax error whenever you finally reach it:

> UPDATE permit SET my_code LIKE ''R'' WHERE old.my_code LIKE new.my_code;

In general you seem to be much too eager to use LIKE where = would do.
= is a lot cheaper, and isn't going to surprise you with odd behavior
on strings containing % or _ ...

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Elphick 2001-11-01 17:36:48 Re: postgres copy
Previous Message Tom Lane 2001-11-01 04:19:40 Re: Returning data from function