[SQL] catch an 'update where false' ?

2005-08-12 Thread santiago
hello

I' trying to catch un update that fails to update because no row matchs
the where clause:

for instance:
update t set c=1 where cc=2;
--and no row with cc=2

I would like to perform a
insert into t (c) values 1;
before the update is resolved

I hoped a trigger before update could help me, but it seems
that if where clause evals to false, triggers are not called..

someone knows a way around this ?

thanks

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] catch an 'update where false' ?

2005-08-14 Thread santiago
Hi

thanks all for your answers !

to Lane Van Ingen:
my purpose is to write a trigger on update so that 'users' might then us
update without having to perform the if found. I don't know if I was
clear about that idea, but the checks on where update will or not
succeed, is what I'm trying to hide from the upper-level users for this
specific table. If what your sugesting works inside such a trigger,
please show my some code of how to do that, beacause it's precisely what
I fail to do.

to Alvaro Herrera :
according to my book, triggers are only implemented whit the FOR EACH
ROW clause in postgres, and not available in the FOR EACH STATEMENT
case. has this changed in some new version ? which shall I use then ?

thanks to both !



Alvaro Herrera wrote:
> On Fri, Aug 12, 2005 at 05:13:24PM +0200, santiago wrote:
>
> Triggers FOR EACH ROW are called once for each updated row.  I think you
> could try with a "FOR EACH STATEMENT" trigger.
>


Lane Van Ingen wrote:
> Don't know where you are doing this, but I can think of a couple ways:
> (1) Do a 'select count(*)  ' on what you are trying to 
> update first to see if it returns a count greater than 0
> (2) If in pl/pgsql functions, you can use the 'IF FOUND' or 'IF NOT FOUND' 
> construct to see if update was successful
> 
> NOTE: I saw that in version 8.1 you will be able to test a PostgreSQL-
> supplied variable, but it is not available until 8.1 release.
> 

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org