0
  • database : postgresql
  • language : plpythonu
  • topic: trigger function
create trigger request_received_trigger 
   after insert on req_table  
for each row 
execute procedure request_received_function();

I need to do something after every insert but the inserted record dose not appear in queries that I make inside request_received_function(). Is inserted record locked inside trigger function?

  1. trigger fires well and I can debug it
  2. on the second insert record is show itself
Pang
  • 9,564
  • 146
  • 81
  • 122
mehdi
  • 2,703
  • 1
  • 13
  • 15
  • 1
    You need to show us the code for the trigger function `request_received_function()`. Why do you make queries inside that function? Are you aware that you can access the inserted row using the `new` record inside the function? http://www.postgresql.org/docs/current/static/plpgsql-trigger.html –  Jan 14 '15 at 07:56
  • Just any select query on req_table, The problem is that queries returns all but the inserted record. And Yes I have access to record through TD['new'] rv = plpy.execute("SELECT * FROM req_table") – mehdi Jan 14 '15 at 08:00
  • 1
    Again: show us the code, this works for me: http://sqlfiddle.com/#!15/801bf/1 Btw: are you sure you want a *row* level trigger if you are selecting from the table? That sounds like a **lot** of overhead. Wouldn't a statement level trigger be more efficient? –  Jan 14 '15 at 08:08
  • if you count the number of records you will see that you are always one behind. http://sqlfiddle.com/#!15/7d355/2 – mehdi Jan 14 '15 at 10:07

0 Answers0