473,394 Members | 1,867 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,394 software developers and data experts.

logically-delete a row rather than actually remove in from table in postgreSQL

I want to write a trigger so that rows deleted from the table are logically-deleted, rather than being actually removed. That is, such rows are marked as being deleted, rather than actually being deleted from the table.

in sql server I know that we can use INSTEAD OF DELETE trigger but I don`t know how can I do the same action in PostgreSQL.

It needed to write a function that update the rows which asked for delete.

please help me with the trigger and related function which is needed .
Sep 13 '07 #1
3 4030
rski
700 Expert 512MB
I want to write a trigger so that rows deleted from the table are logically-deleted, rather than being actually removed. That is, such rows are marked as being deleted, rather than actually being deleted from the table.

in sql server I know that we can use INSTEAD OF DELETE trigger but I don`t know how can I do the same action in PostgreSQL.

It needed to write a function that update the rows which asked for delete.

please help me with the trigger and related function which is needed .
In postgres u have rules (in which u can use instead) and u can use triggers 'after' which do some updates and return null.
Give more informations about u'r problem.
Sep 13 '07 #2
In postgres u have rules (in which u can use instead) and u can use triggers 'after' which do some updates and return null.
Give more informations about u'r problem.
Thanks for your help .
I want to write a trigger that acts like this:
When a user executes a DELETE statement, the trigger must set the WhenDeleted value to the system’s CURRENT_TIMESTAMP value, for each of the rows targeted by that DELETE statement.
Sep 15 '07 #3
rski
700 Expert 512MB
Thanks for your help .
I want to write a trigger that acts like this:
When a user executes a DELETE statement, the trigger must set the WhenDeleted value to the system’s CURRENT_TIMESTAMP value, for each of the rows targeted by that DELETE statement.

i don't see the trigger, so i write it

CREATE FUNCTION LogicalDeleteFunction ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
declare
t timestamp;

BEGIN
t=current_timestamp;
UPDATE patients
SET
patients.whendeleted = current_timestamp
JOIN deleted ON deleted.patientnum = patients.patientnum
??no where clause
what is deleted table??


return OLD;
END;
$$;

create trigger my_trig before delete on patients for each row execute procedure LogicalDeleteFunction ();
Sep 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

72
by: Wim Vanhoof | last post by:
Dear all, I would like to announce that the department of computer science of the University of Namur, Belgium, is seeking a post-doctoral researcher for a one-year fellowship in the area of ...
7
by: Klaus Neuner | last post by:
Hello, I need a function that converts a list into a set of regexes. Like so: string_list = print string_list2regexes(string_list) This should return something like:
3
by: Math Preregistration System | last post by:
I'm using a std::list as a container for some pointers to objects, for example list< C* > lst; I would like to sort them using two different criteria, say first by C.first and then by...
4
by: HS-MOON | last post by:
I'm asking you to help me. I'm a beginner of studying c++. I'm trying to make the Singly Linked List(Ordered). Anyway, I've been debugging all day. I can't sort it out!! As you see, I don't...
49
by: Alex Vinokur | last post by:
Are there any restrictions/problems for use of C++ STL in development in embedded systems? In particular: * Does STL require too much space/memory? * Is 'implementation of STL...
8
by: shawnk | last post by:
Given several nullable boolean flags; bool? l_flg_01 = true; bool? l_flg_02 = false; bool? l_flg_03 = true; bool? l_result_flg = null; I would have liked...
1
by: Rasheed | last post by:
We are building a smart client application (.NET 2.0) which uses Web Services to access the business objects. Services: The Web Services have been secured by brokered authentication using X509...
62
by: Born | last post by:
GC is really garbage itself Reason 1: There is delay between the wanted destruction and the actual destruction.
25
by: beginner | last post by:
Hi, I am wondering how do I 'flatten' a list or a tuple? For example, I'd like to transform or ] to . Another question is how do I pass a tuple or list of all the aurgements of a function to...
6
by: Tarique | last post by:
Can someone please explain the idea of Logical Constness as explained in section 10.2.7.1 Of Stroustrup's "The C++ Programming Language" ,with a short working code if possible. Thank You
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.