1

How can I create triggers within a stored procedure in VoltDB?

I am using the C# VoltDB client. Is the callback in voltdb.procedures.wrap() the same as creating triggers?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Cenoy
  • 21
  • 1

1 Answers1

1

VoltDB doesn't support traditional triggers, however a stored procedure can contain multiple SQL statements and logic that allow transactions to go through if certain conditions are met. The callback in voltdb.procedures.wrap() is where you can code what happens after a response. It can work as a sort of 'trigger' for all intents and purposes.

Full disclosure: I work at VoltDB.

Andrew
  • 311
  • 1
  • 8
  • Thanks, Andrew. Could you please give an example or any link about multiple SQL statements like a scenario , for every 10 rows in a table , need to insert "some text" into another table. – Cenoy Jun 12 '18 at 04:39
  • Take a look at Designing Stored Procedures (https://docs.voltdb.com/UsingVoltDB/DesignProc.php) for how to write a procedure. This example inserts, selects, and sometimes does more inserts: https://github.com/VoltDB/voltdb/blob/master/examples/bank-offers/procedures/bankoffers/CheckForOffers.java – BenjaminBallard Jun 12 '18 at 13:52
  • For "every 10 rows" you would just want to be careful to ensure the procedure is deterministic. This could be done using VoltProcedure.getSeededRandomNumberGenerator() https://docs.voltdb.com/javadoc/procedure-api/org/voltdb/VoltProcedure.html#getSeededRandomNumberGenerator-- or you could use getUniqueId https://docs.voltdb.com/javadoc/procedure-api/org/voltdb/VoltProcedure.html#getUniqueId-- and a mod function to do something approximately every 10 times deterministically. – BenjaminBallard Jun 12 '18 at 13:55
  • Thank you very much Andrew again.As I mentioned earlier, I am using C# VoltDB client and I could not find statements like public final SQLStmt insertActivity = new SQLStmt("INSERT INTO XXXX VALUES ( ?,?,?,?,?,?,?);") But I am able to insert, update , upsert and delete using voltDB.Procedures.Wrap<> and Select.Execute(). About the Scenario , I am inserting into table X and whenever the count reached 10 records (10,20,30,....etc) I need to trigger an insert into table Y. Could you please help me to sort out this. – Cenoy Jun 13 '18 at 04:56