# Delete records older than (Transaction Groups) - How does this work?

**URL:** <https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [July 9, 2020, 12:45pm UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532 "2020-07-09T12:45:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbackus](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tbackus/32/5091_2.png) [@tbackus](https://forum.inductiveautomation.com/u/tbackus)\
**Post date:** [July 9, 2020, 12:45pm UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532/1 "2020-07-09T12:45:44Z")

</div>

Question, when this setting is turned on, does this do a delete row as part of the same query call to SQL? or does it issue a second query immediately before or after the insert query?

Just curious.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 9, 2020, 4:41pm UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532/2 "2020-07-09T16:41:52Z")

</div>

It’s a separate task issuing its own queries as needed.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [July 10, 2020, 6:37am UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532/3 "2020-07-10T06:37:07Z")

</div>

A vendor once told me this:

Es. for “Delete Records older than” **X** :

- X \< 1 hour, the delete task execute every minute
- 1 hour\< X \<12 hours, every 15 minutes
- X \> 12 hours, every hour

Of course in addition to @paul-griffith’s answer 😉

---

<div class="post-metadata">

**Author:** ![Jose\_Vergara](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@Jose\_Vergara](https://forum.inductiveautomation.com/u/Jose_Vergara)\
**Post date:** [January 7, 2022, 10:14pm UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532/4 "2022-01-07T22:14:26Z")

</div>

How does it determine how old a record is?  
I have a transaction group that only updates the t\_stamp of a record when a certain device id is read and set it to delete records older then 90 days. It seems to delete records that were first created 90 days ago even if they were just updated today.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 7, 2022, 10:25pm UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532/5 "2022-01-07T22:25:33Z")

</div>

I can promise SQLBridge doesn’t have any knowledge of anything beyond what’s in the database. However, it’s not just a straightforward ‘prune everything with an age \> x’; the actual logic looks like this:

```java
String ndxQuery = String.format("SELECT max($%s$) FROM %s WHERE $%s$<?", indexCol, tableName, tsCol);
String deleteQuery = String.format("DELETE FROM %s WHERE $%s$<=?", tableName, indexCol);
deleteTime = new Timestamp(conn.getCurrentDatabaseTime() - deleteAge);
ndx = conn.runScalarPrepQuery(ndxQuery, deleteTime);
if (ndx != null) {
    conn.runPrepUpdate(deleteQuery, ndx);
}

```

---

<div class="post-metadata">

**Author:** ![Jose\_Vergara](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@Jose\_Vergara](https://forum.inductiveautomation.com/u/Jose_Vergara)\
**Post date:** [January 7, 2022, 11:00pm UTC](https://forum.inductiveautomation.com/t/delete-records-older-than-transaction-groups-how-does-this-work/36532/6 "2022-01-07T23:00:27Z")

</div>

That explains the behavior. For what I’m doing, I’ll have to use a scheduled gateway event then.

Thanks!
