# Non-unique block\_id from block transaction group?

**URL:** <https://forum.inductiveautomation.com/t/non-unique-block-id-from-block-transaction-group/12596>\
**Category:** Ignition\
**Created:** [January 24, 2017, 5:32pm UTC](https://forum.inductiveautomation.com/t/non-unique-block-id-from-block-transaction-group/12596 "2017-01-24T17:32:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [January 24, 2017, 5:32pm UTC](https://forum.inductiveautomation.com/t/non-unique-block-id-from-block-transaction-group/12596/1 "2017-01-24T17:32:34Z")

</div>

Is the block\_id from a block transaction group always unique? Or are there certain things I could have done which would have caused it to reset to 1? For instance, does modifying a group and then saving it cause the block\_id to reset? What about changing the group name?

Here is my situation. I have a block transaction group which writes to table\_staging in the database. Then I have a job on the SQL server that does some calculations and modifications, verifies these new rows have not already been moved, and moves that data to table\_final and deletes the rows from table\_staging.

Yesterday afternoon, it stopped moving the data to table\_final, and it turns out that it is because the block\_ids already exist there, so it thought they would be duplicated. I can go through and fix the data this time, but I need to know if it is going to reset the block\_id again so I can stop assuming that is going to be unique.

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [January 24, 2017, 6:52pm UTC](https://forum.inductiveautomation.com/t/non-unique-block-id-from-block-transaction-group/12596/2 "2017-01-24T18:52:43Z")

</div>

Hi,

When inserting, the block group select the max(block\_id), and then adds 1 to it. If you are moving rows out of that table, it might be a bit unpredictable as to what you’d end up with. If the move and clear happened before the group ran, you would/should end up with 1 for the next execution.

Two solutions come to mind: 1) Mark your blocks as transferred, and when you delete, don’t delete the most recent… or 2) instead of using the “store block id” option, use 2 Query items in the group: one that selects the current “block id” from an outside table that you’ve created and is set to write to the “block\_id” column, and and one that then runs an update query to update that value in the outside table.

Actually, you could probably achieve that 2nd id with Tags as well- create a memory tag that you then reference in the group as a “read only” item… execept I think you can then use it as the write target of an expression item whose value is “{BlockId}+1”. Since it’s a memory tag in an actual tag provider, the value will persist across group and gateway restarts.

Regards,

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [January 24, 2017, 7:46pm UTC](https://forum.inductiveautomation.com/t/non-unique-block-id-from-block-transaction-group/12596/3 "2017-01-24T19:46:50Z")

</div>

Great, thanks for the details and suggestions! I think I’ll try option 1 first, since I can fit that logic into my existing stored procedure.
