| From: | "K Parker" <kparker(at)eudoramail(dot)com> |
|---|---|
| To: | pgsql-general(at)hub(dot)org |
| Subject: | re: insert or update |
| Date: | 2000-06-23 20:42:53 |
| Message-ID: | KKCMHMHFOAACFAAA@shared1-mail.whowhere.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
This looks scary to me:
> CREATE FUNCTION names_trig() RETURNS OPAQUE AS '
> DECLARE
> rec names%ROWTYPE;
> BEGIN
> IF TG_OP = ''INSERT'' THEN
> SELECT * INTO rec FROM names WHERE name = NEW.name;
> IF FOUND THEN
> UPDATE names SET age = NEW.age WHERE name = NEW.name;
> RETURN NULL;
> END IF;
> RETURN NEW;
> END IF;
Shouldn't that say 'select FOR UPDATE'? Otherwise there's a window of opportunity for others to do something to that row. Also, though this is clearly meant as a simple example, it's worth pointing out explicitly that this approach is really only safe when the key you're using is unique.
Join 18 million Eudora users by signing up for a free Eudora Web-Mail account at http://www.eudoramail.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruce Momjian | 2000-06-24 01:47:35 | Re: Is this still true? |
| Previous Message | Denis Perchine | 2000-06-23 18:48:53 | Re: Re: [GENERAL] libpq error codes |