problem with function to report how many records were changed - Mailing list pgsql-general

From
Subject problem with function to report how many records were changed
Date
Msg-id 20031015195539.DDBB846E27@mail.passofundo.rs.gov.br
Whole thread Raw
Responses Re: problem with function to report how many records were changed
Re: problem with function to report how many records were
List pgsql-general
Hi,
I intend to get some answer from postgres concerning if an update command
has altered some records in the database.
To do this I coded this function:

create or replace function upd_ok(text,text,text,text) returns integer
as '
declare
   table alias for $1;
   field alias for $2;
   val1 alias for $3;
   val2 alias for $4;
begin
  execute ''update '' || quote_ident(table) || '' set '' ||
quote_ident(field) '' = '' || quote_literal(val1) ||
              '' where '' || quote_ident(field) || '' = '' ||
quote_literal(val2);
   if found then
      raise notice ''ok'';
   else
      raise exception ''not found'';
   end if;
   return 1;
end;
'
language 'plpgsql';

---

This function takes four parameters for the update command and then warn the
user if the update command has performed any change. The problem is I tested
this function with tables, fields and values correct, and the function still
reports that no record was altered. Issuing the update manually the changes
are made. I think this is kind of strange, so I'm sending this to the list.
I am using postgresql version 7.2.3
If there are any unimplemented features, how else could I know if an update
command altered records?

Thanks in advance,
Enio

pgsql-general by date:

Previous
From: "Miquel van Smoorenburg"
Date:
Subject: Re: Humor me: Postgresql vs. MySql (esp. licensing)
Next
From: "Matthew T. O'Connor"
Date:
Subject: Re: VACUUM degrades performance significantly. Database