473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

automatic update

Hi to all ...

I'm looking to a way to auto update some fields of a row when other
fileds are updated.

the table structure are simple,

CREATE TABLE param (
id int4 PRIMARY KEY,
val int4,
ts timestam(3) DEFAULT CURRENT_TIMESTAMP
);

so when a new entry are insert ts areautomatically update,
but i would make the same on update ...

i would that on
UDPATE param SET val=100 WHERE id=1;

also ts field have to be updated to CURRENT_TIMESTAMP

I try with a RULE but obtain only a loop, seem RULE aren't good to make
such things, modify a statment on the same table it's related :(

i look for a trigger but I suppose the same problem arise ...

how i can solve the problem ???

mhhh does i have to have a VIEW of parm ... called param2 without the ts
field and make a rule on param2 that update param.ts ???
seem a bit tricky :( ...

thanks in advance ...
--
Alessandro GARDICH <gr*****@gremlin.it>
gremlin.it

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

Nov 11 '05 #1
1 2385
A trigger is the right way. Rules rewrite a statement whereas triggers are at
row level.

so in plpgsql:

create or replace function trig_param_ins_upd() returns trigger as '
begin
new.ts = current_timestamp;
return new;
end;' language 'plpgsql';

create trigger trig_param_ins_upd before insert or update on param
for each row execute procedure trig_param_ins_upd();

now whenever a new row is insert or a row is updated the trigger will ensure
that ts always contains the current timestamp.

Rgds,

Jason

On Tue, 2 Sep 2003 06:56 pm, Alessandro GARDICH wrote:
Hi to all ...

I'm looking to a way to auto update some fields of a row when other
fileds are updated.

the table structure are simple,

CREATE TABLE param (
id int4 PRIMARY KEY,
val int4,
ts timestam(3) DEFAULT CURRENT_TIMESTAMP
);

so when a new entry are insert ts areautomatically update,
but i would make the same on update ...

i would that on
UDPATE param SET val=100 WHERE id=1;

also ts field have to be updated to CURRENT_TIMESTAMP

I try with a RULE but obtain only a loop, seem RULE aren't good to make
such things, modify a statment on the same table it's related :(

i look for a trigger but I suppose the same problem arise ...

how i can solve the problem ???

mhhh does i have to have a VIEW of parm ... called param2 without the ts
field and make a rule on param2 that update param.ts ???
seem a bit tricky :( ...

thanks in advance ...

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #2

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

Similar topics

6
by: Aaron Ackerman | last post by:
Is anyone familiar with that Automatic/Automated Update feature for .NET WinForms apps which essentially allow a user to hit a server for their data (even over the Internet) possibly and have their...
6
by: Gert van der Kooij | last post by:
Hi, It's no problem to define the automatic maintenance using the wizard but I want to use commands to automate automation. I captured the SQL statements when activating the maintenance but that...
0
by: Justin Beckwith | last post by:
As a development project I've been working on comes to a close, I am starting to contemplate including my own automatic update system. I have a rather sizable ASP.NET application that is being...
2
by: anony | last post by:
Maybe this feature is already out there. I guess you could write triggers to do some of this. Often when designing a database I add a start_date and end_date column to the table. The start_date...
1
by: Chris Weston | last post by:
Hi. I have automatic statistic update turned on for all my databases. Is this an overhead I can do without? Could I update them overnight when the database is hardly in use? Thanks --...
1
by: rdemyan via AccessMonster.com | last post by:
My App has 10 or so tables that we provide that contains proprietary data. This data will need to be updated once or twice a year. I would like some comments, suggestions on my proposed strategy...
1
by: =?Utf-8?B?RGF2ZSBDdW5uaW5naGFt?= | last post by:
I'm new at this so I hope I get it right THIS time! Running Windows XP SP2. When I boot up I get the following message: RUNDLL Error loading C:\WINDOWS\SYSTEM32\valcesfk.dll The specified...
4
by: =?Utf-8?B?Zmx5ZXJk?= | last post by:
I have win xp home, automatic updates set for auto at 3:00 am. The download and install happens. (Proved by looking on web update history and in windows directory) however the yellow icon w/ the...
1
by: =?Utf-8?B?UHNldQ==?= | last post by:
Hello. System: Win XP Media Centre Edition – Service Pack 3 Somehow, I picked up a variant of VirtuMonde; Symantec Anti-virus, Spybot Search & Destroy etc did not locate it; I discovered it...
20
by: Constantine AI | last post by:
Hi I have this code which i thought was perfect maybe a bit of a mess but it works. The only problem is that the rst!PONo does not look at the table properly and generate a continuing number, which i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.