can you use variables in PostgreSQL rules?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vassilev, Lubomir G.

    #1

    can you use variables in PostgreSQL rules?

    i am currently migrating a db from Oracle to Pg and in some of my
    triggers i use variables, i.e. i have some thing like this:



    [Oracle version]



    CREATE OR REPLACE TRIGGER "USERACTION_VIE W" INSTEAD OF INSERT ON
    "USERACTION_VIE W" DECLARE

    UserActionID INTEGER;

    UserActionDataI D INTEGER;

    begin

    SELECT USERACTION_SQ.n extval into UserActionID FROM DUAL;

    SELECT USERACTIONDATA_ SQ.nextval into UserActionDataI D FROM DUAL;



    INSERT INTO USERACTION

    (

    UserActionID,

    LocalID,

    UserActionTypeI D,

    ActionDate

    )

    VALUES

    (

    UserActionID,

    :new.LocalID,

    :new.UserAction TypeID,

    SYSDATE

    );



    INSERT INTO USERACTIONDATA

    (

    UserActionDataI D,

    UserActionID,

    AccountID,

    CourseRecordID,

    CourseRecordPay mentID,

    StudentID,

    CourseRecordTes tID,

    CourseRecordLes sonID

    )

    VALUES

    (

    UserActionDataI D,

    UserActionID,

    :new.AccountID,

    :new.CourseReco rdID,

    :new.CourseReco rdPaymentID,

    :new.StudentID,

    :new.CourseReco rdTestID,

    :new.CourseReco rdLessonID

    );



    end;





    so basically i have two variables here, UserActionID and
    UserActionDataI D. so when i am porting to PostgreSQL i will need to make
    this a rule since Pg triggers only work for tables. The problem though
    is that i don't know how to use variabvles in Pg rules. Any ideas? Is it
    possible at all?



    Thanks.


Working...