2

Is it possible to create a trigger that outputs a CSV file selecting Fields 1 from Table 1 right after Table 2 is updated?

I have tried using

CREATE OR ALTER trigger test_a0 for Table 2
active after insert or update position 0
AS
begin

  if (updating and new.field1 is not null) then
  output ('C:\test\test.csv');
  select field1 from table1;
  output;
  commit;

end
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • you try may do it via External Tables, if you would assure all the rows have exactly the same pre-defined length in characters and pad the too short line and cut the too long lines. but the very idea to force internal inside-DB processes being dependent upon external conditions (like writing into CSV files) is a quite bad one. Make your trigger issue events ,and make a stand-alone deamon program, that waits for those events and then creates those CSV files. – Arioch 'The Apr 14 '17 at 11:31

2 Answers2

2

No, this it is not possible to output to a CSV file in triggers in Firebird 2.5. If you want to output to a file, you either need to do that in a client application, or use an external table (which technically is a binary format, not a text format). It might be possible to create a convoluted solution using UDFs.

In Firebird 3, a simpler solution might be possible using a UDR (User Defined Routines), but this is largely unknown territory, so I'm not actually sure if it can be done that way.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
1

I suppose you can do it with IBExpert tools ibeblock

 execute ibeblock
 as
 begin
  txt='';
  for
   select firstname, lastname
   from customer
   into :fn,:ln
   do
   begin
      txt=txt+fn+';'+ln+ibec_crlf();
   end;
   ibec_SaveToFile('C:\txt.csv',txt,__stfOverwrite);
 end
Hugues Van Landeghem
  • 6,755
  • 3
  • 34
  • 59
  • Interbase Expert is a stand-alone tool, it does not work from within FB *triggers* which is DB-internal process – Arioch 'The Apr 14 '17 at 11:29