0

Hi im trying to create a trigger after insert on the tUser table.

I made my trigger function and it connected.

Now i get an error saying: column "cnewusername" of relation "tAuditUser" does not exist. Now this is the first value of my tAuditUser table, so i guess the problem will continue throughout the values.

This is my code:

create or replace function auditUserInsert() returns trigger as $userAuditInsert$
begin
insert into public."tAuditUser"
( 
    cNewUsername, 
    cNewPassword, 
    cNewEmail, 
    cNewPhoneNumber, 
    nPhoneCodeID, 
    nCountryCodeID, 
    dJoinDate)
values
(
    new.cUsername,
    new.cPassword, 
    new.cEmail, 
    new.cPhoneNumber, 
    new.nPhoneCodeID,   
    new.nCountryCodeID,  
    current_timestamp
);
return new;
end;
$userAuditInsert$ language plpgsql;


create trigger trgAuditUserInsert after insert on public."tUser"
for each row execute procedure auditUserInsert();

The user i add has the values:

INSERT INTO public."tUser"("cUsername", "cPassword", "cEmail", "cPhoneNumber", "nPhoneCodeID", "nCountryCodeID")
    VALUES ('Testname', '123', 'e@e.dk', '88888888', 1, 1);

Note: My user is added to the database

  • You should really avoid those dreaded quoted identifiers. They are much more trouble than they are worth it. https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_upper_case_table_or_column_names –  May 15 '20 at 15:42
  • `"cNewUsername"` not `cNewUsername` –  May 15 '20 at 15:43
  • Thanks for the reply. Still same error with "" – Elias Marco Lip May 15 '20 at 15:50

0 Answers0