473,788 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with function to report how many records were changed

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,tex t,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(tab le) || '' set '' ||
quote_ident(fie ld) '' = '' || quote_literal(v al1) ||
'' where '' || quote_ident(fie ld) || '' = '' ||
quote_literal(v al2);
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 YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 12 '05 #1
2 1698
<en**@pmpf.rs.g ov.br> writes:
execute ''update '' || quote_ident(tab le) || '' set '' ||
quote_ident(fie ld) '' = '' || quote_literal(v al1) ||
'' where '' || quote_ident(fie ld) || '' = '' ||
quote_literal(v al2);
if found then
I don't believe EXECUTE sets FOUND. You'll need to do something else,
perhaps use FOR IN EXECUTE.
I am using postgresql version 7.2.3


You'll probably also need to use a newer Postgres release; IIRC 7.2
didn't set FOUND properly in for-loops.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #2
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 en**@pmpf.rs.go v.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,tex t,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(tab le) || '' set '' ||
quote_ident(fie ld) '' = '' || quote_literal(v al1) ||
'' where '' || quote_ident(fie ld) || '' = '' ||
quote_literal(v al2);
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 YourEmailAddres sHere" to ma*******@postg resql.org)


--
Darren Ferguson
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
14023
by: GL | last post by:
I am running DB2 8.1.1 on AIX 5.1 Having a problem with a redirected restore. Once into the restore continue phase, I immediately get the following “SQL2059W A device full warning was encountered on device "TBS_IDX". Do you want to continue(c), terminate this device only(d), abort the utility(t) ? (c/d/t) t
5
14896
by: BlackFireNova | last post by:
I need to write a report in which one part shows a count of how many total records fall within the working days (Monday - Friday) inside of a (prompted) given date range, in a particular geographical region. I have written a query which prompts the user for the start and end dates. It also filters for entries which pertain to the particular geographical region. I'm not sure where to go from here.
1
1675
by: MHenry | last post by:
Hi, I have a table with duplicate records. Some of the duplicates need to be eliminated from the table and some need not. A duplicate record does not need to be eliminated if the one record appears multiple times on one employee's report. However, if the same record(s) appear on any other employee's report, it means they collaborated on the item, and the item from the second employee's report should be eliminated from the table.
1
3129
by: CSDunn | last post by:
Hello, In an Access 2003 Project that uses a SQL Server 2000 database as its data source, I am attempting to set the RecordSource property of a sub report called 'RptTeacherHistory2' that appears in several different 'main' reports. I have tried to use the following code; Me.RptTeacherHistory2.Properties("RecordSource") = "EXEC RCTeacherHistory_sp " & Me.Permnum 'RCTeacherHistory' is a proc that takes 'permnum' as a single
3
2109
by: Peter | last post by:
Dear all, Would you tell me how to solve the following two problems in an access file upon preparing report form: a) I have written an IIf function for a string field at the beginning of group row of a report form as below: sss is a string field with 2 characters; the function is = IIf(="1", "yes","no")
1
2510
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals. first, let me say that this is a really long post. i wasn't sure how much information/ background to provide, so i thought more was better than less. i tried to delineate certain areas so that it would be easy to peruse my posting and find...
6
2566
by: geronimo_me | last post by:
I have 20 queries that compare fields in one table with fields in another table - the query results are the records that do not match in Table1 and Table2. ie Table1 DOB 28/02/78 Table2 DOB 27/02/78
3
2063
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few parameters...." I have read many articles on the web about how to make a dynamic report based on a cross-tab query. But for some reason mine never works right. First, my saved query's criteria is the data in an open form's combo box. So the...
2
3016
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.