Re: problem with function to report how many records were

From: darren(at)crystalballinc(dot)com
To: enio(at)pmpf(dot)rs(dot)gov(dot)br
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problem with function to report how many records were
Date: 2003-10-16 18:07:45
Message-ID: Pine.LNX.4.44.0310161406540.31986-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You should look at the GET_DIAGNOSTICS functionality provided by Postgres
There it supports ROWCOUNT and this gives you the number of rows affected
by the UPDATE command

HTH

Darren

On Wed, 15 Oct 2003 enio(at)pmpf(dot)rs(dot)gov(dot)br wrote:

> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>

--
Darren Ferguson

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark Harrison 2003-10-16 18:47:17 maximum number of client connections?
Previous Message Bruno Wolff III 2003-10-16 17:59:16 Re: UPDATE table to a joined query...