problem with function to report how many records were changed

From: <enio(at)pmpf(dot)rs(dot)gov(dot)br>
To: <pgsql-general(at)postgresql(dot)org>
Subject: problem with function to report how many records were changed
Date: 2003-10-15 19:55:39
Message-ID: 20031015195539.DDBB846E27@mail.passofundo.rs.gov.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gene Vital 2003-10-15 20:08:26 ODBC
Previous Message Stephen 2003-10-15 19:27:22 Re: VACUUM degrades performance significantly. Database