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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mitramirsa
    New Member
    • Sep 2007
    • 2

    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 .
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by Mitramirsa
    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.

    Comment

    • Mitramirsa
      New Member
      • Sep 2007
      • 2

      #3
      Originally posted by rski
      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_TIMESTA MP value, for each of the rows targeted by that DELETE statement.

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        Originally posted by Mitramirsa
        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_TIMESTA MP value, for each of the rows targeted by that DELETE statement.

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

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

        BEGIN
        t=current_times tamp;
        UPDATE patients
        SET
        patients.whende leted = current_timesta mp
        JOIN deleted ON deleted.patient num = patients.patien tnum
        ??no where clause
        what is deleted table??


        return OLD;
        END;
        $$;

        create trigger my_trig before delete on patients for each row execute procedure LogicalDeleteFu nction ();

        Comment

        Working...