sql - Postgres trigger after insert accessing NEW -
itemprop = "text"> I have a very simple trigger:
can be created or repositioned FUNCTION f_log_datei ( ) Log back in to TRIGGER $$ (Actions, Tabel, Bennetzer_ID) Value (TGOP, 'Dedan', New. Banner_ID); End; $$ language 'plpgsql'; The process executed by each statement f_log_datei (); After updating or removing or deleting the date, create the logger_log_data.
My table log is as follows:
CREATE TABLE logs (ID int primary key default NEXTVAL ('logs_id_seq'), now the title timestamp default (), Ekton Kerr (6), Tabell Warker (32), Alt Varkar (256), Nur Vararar (256), Bennetzer_IndeInte Banner (ID) references);
After entering something into the files, I get the following error:
Error: The record "new" is not assigned yet: DETAIL does not have one taple The structure-assigned assign records are uncertain. Context: Enter the SQL statement "Log (Aktion, tabelle, benutzer_id) value (TG_OP, 'files', NEW.benutzer_id)" PL / pgSQL function "f_log_datei" SQL statement line 3 < / Code>
Why did I get this error? I looked into the documentation and it seems that they use it in a new way the same way.
/ Strong>
[...]
For a row-level trigger, enter
NEW
in line
INSERT
and
UPDATE code> trigger, and / or OLD
for the line UPDATE
and DELETE
. Statement-level triggers There is currently no way to check individual row (s) modified by the statement. and from:
new
data type records
; The variable that holds the new database line for INSERT
/ UPDATE
is in the row-level trigger. This variable is for NULL
statement level triggers and DELETE
functions.
Note that this line-level triggers and statement -live trigger.
You have a statement-level trigger:
... process executed for each statement f_log_datei (); Statement-level triggers are triggered once per statement, and one statement can be applied to multiple rows, so that the affected row (which is NEW
and about OLD
are not applicable). If you want to use NEW
(or OLD
) in a trigger then you trigger to execute for each affected row And this means that you are a line-level trigger:
After inserting or updating, you can create TRIGGER log_datei or DELETE RAW out execution process on files for each f_log_datei () ;
I have just changed for every statement
to for each line
.
Also need your trigger:
A trigger function should return either NULL
or a record / row value The table was properly triggered.
. .]
The return value of a line-level trigger is removed after
or a statement-level trigger is removed by first
or after
are given ; It may also be as null as well, however, any of these types of triggers can still cause an entire operation by lifting the error.
Then you should new Return;
or returns zero; In your trigger
you have one after the trigger, so no matter what returns you use, but I back new;
.
No comments:
Post a Comment