Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

triggers - postgre how to append (COPY ? ) the last inserted row (NEW) to a file

I am trying to create a trigger in a postgre (9.6) database. My goal is to apped the last inserted row to a file. I can make it work by COPYing the whole table with the following code. My questions are : how to append data with COPY ? and how to use only the last inserted row ? Here is my code.

create function test_function() returns trigger as $test_trigger$
  begin
    copy (select * from my_table) to 'C:Tempstats.txt';
    return NEW;
  end;
$test_trigger$ language plpgsql;

create trigger test_trigger after insert on my_table
for each row
execute procedure test_function();
question from:https://stackoverflow.com/questions/65904277/postgre-how-to-append-copy-the-last-inserted-row-new-to-a-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...