# Get commit transaction ID inside iter() func

**URL:** <https://dmap-community.ductus.global/t/get-commit-transaction-id-inside-iter-func/490>\
**Category:** CDB and CDB API\
**Created:** [May 19, 2016, 5:37pm UTC](https://dmap-community.ductus.global/t/get-commit-transaction-id-inside-iter-func/490 "2016-05-19T17:37:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yogevc](https://avatars.discourse-cdn.com/v4/letter/y/8491ac/32.png) [@yogevc](https://dmap-community.ductus.global/u/yogevc)\
**Post date:** [May 19, 2016, 5:37pm UTC](https://dmap-community.ductus.global/t/get-commit-transaction-id-inside-iter-func/490/1 "2016-05-19T17:37:23Z")

</div>

Hi,  
Is it possible, and if so, how, to get the commit transaction ID from inside the subscribed `iter()` function?  
Or before calling the `iter()` function?

I want to know when is the first time an iter function is called and when is the last time it’s being called in a commit transaction.

Thanks.

---

<div class="post-metadata">

**Author:** ![jjohansson](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jjohansson](https://dmap-community.ductus.global/u/jjohansson)\
**Post date:** [May 19, 2016, 5:59pm UTC](https://dmap-community.ductus.global/t/get-commit-transaction-id-inside-iter-func/490/2 "2016-05-19T17:59:01Z")

</div>

Hi,  
Does cdb\_get\_txid() do what you want?

---

<div class="post-metadata">

**Author:** ![yogevc](https://avatars.discourse-cdn.com/v4/letter/y/8491ac/32.png) [@yogevc](https://dmap-community.ductus.global/u/yogevc)\
**Post date:** [May 19, 2016, 7:04pm UTC](https://dmap-community.ductus.global/t/get-commit-transaction-id-inside-iter-func/490/3 "2016-05-19T19:04:42Z")

</div>

I’ll try using it! Thanks!

---

<div class="post-metadata">

**Author:** ![per](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@per](https://dmap-community.ductus.global/u/per)\
**Post date:** [May 19, 2016, 7:32pm UTC](https://dmap-community.ductus.global/t/get-commit-transaction-id-inside-iter-func/490/4 "2016-05-19T19:32:39Z")

</div>

But calling it from inside iter() doesn’t make sense - the sequence of events **for one notification** is: 1) call cdb\_read\_subscription\_socket(), followed by one sequence per subscription point of 2) invoke cdb\_diff\_iterate() -\> one or more invocations of iter() -\> cdb\_diff\_terate() returns. All the iter() invocations originating from one call of cdb\_read\_subscription\_socket() pertain to the same notification, and thus necessarily are from one and the same transaction. Thus calling cdb\_get\_txid() **once** in the complete sequence (e.g. before the first invocation of cdb\_diff\_iterate()) is sufficient. However you still won’t know that one such sequence is the last for a given transaction until you get a notification for **another** transaction.

You probably want to combine this with using cdb\_read\_subscription\_socket2() instead of cdb\_read\_subscription\_socket(), and checking the CDB\_SUB\_FLAG\_IS\_LAST flag. That way you a) only need to call cdb\_get\_txid() **once per transaction** , and b) can tell when you have received all the notifications for a given transaction.
