| From: | Michael Fuhr <mike(at)fuhr(dot)org> |
|---|---|
| To: | operationsengineer1(at)yahoo(dot)com |
| Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Re: Update & Lack of Error Message |
| Date: | 2006-01-27 02:59:22 |
| Message-ID: | 20060127025922.GA576@winnie.fuhr.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
On Thu, Jan 26, 2006 at 04:13:45PM -0800, operationsengineer1(at)yahoo(dot)com wrote:
> i can run the query, check for rows updated and then
> do whatever makes sense from that point.
>
> a zero row update can still mean two things, though -
> the serial doesn't exist or the serial exists, but
> already has been updated to the new value. i need to
> decide if that distinction will be important enough to
> differentiate the error messages.
If the "already updated" case is important then be aware that a row
will be counted as updated even if its new and old values are the
same.
test=> SELECT * FROM foo;
id | x
----+---
1 | 2
(1 row)
test=> UPDATE foo SET x = 2 WHERE id = 1;
UPDATE 1
If you want an "already changed" update to return zero rows then
add a condition to check that the column has a different value than
the one you're assigning:
test=> UPDATE foo SET x = 2 WHERE id = 1 AND x <> 2;
UPDATE 0
You might want to use IS DISTINCT FROM instead of <> if x can be
NULL.
--
Michael Fuhr
| From | Date | Subject | |
|---|---|---|---|
| Next Message | s21113298 | 2006-01-27 09:51:35 | Password Authentication Error |
| Previous Message | operationsengineer1 | 2006-01-27 00:13:45 | Re: Update & Lack of Error Message |