# Are table operations atomic?

**URL:** <https://forum.kx.com/t/are-table-operations-atomic/6984>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [February 13, 2011, 12:54pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984 "2011-02-13T12:54:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyturk](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andyturk](https://forum.kx.com/u/andyturk)\
**Post date:** [February 13, 2011, 12:54pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/1 "2011-02-13T12:54:00Z")

</div>

In a traditional ACID database, when an error occurs inside atransaction, any updates made previously in the transaction are eitherrolled back or simply thrown away.I expected q’s table operations to behave the same way. However, thisappears not to be the case. Consider the following example:KDB+ 2.7 2010.11.30 Copyright (C) 1993-2010 Kx Systemsm32/ 2()core 4096MB andy mini.private 255.255.255.255 PLAY 2011.02.28q)t:( c1:`a`b`c; c2:10 20 30)q)@[`t;0;:;(`aa;99f)]'typeq)tc1 c2-----aa 10b 20c 30The partial update to the first column survives even though theoverall call to @ fails. The same thing happens with directassignment:q)t[0]:(`bb;98f)'typeq)tc1 c2-----bb 10b 20c 30Really?

---

<div class="post-metadata">

**Author:** ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)\
**Post date:** [February 15, 2011, 3:28am UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/2 "2011-02-15T03:28:00Z")

</div>

Take a look at:

[https://code.kx.com/trac/wiki/Cookbook/Logging](https://code.kx.com/trac/wiki/Cookbook/Logging)

---

<div class="post-metadata">

**Author:** ![petrum1](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@petrum1](https://forum.kx.com/u/petrum1)\
**Post date:** [February 15, 2011, 10:15pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/3 "2011-02-15T22:15:00Z")

</div>

Thanks for link.I’ve tried it, but I cannot get it to automatically rollback, and getthe initial table when the update fails.The original data is restored (from logs) only if I restart the qprocess.Is this the way it is supposed to work?PMOn Feb 14, 10:28?pm, Tim Rieder \<trie…\> wrote:\> Take ?a look at:\>\> [https://code.kx.com/trac/wiki/Cookbook/Logging&gt;&gt](https://code.kx.com/trac/wiki/Cookbook/Logging&gt;&gt); On Sun, Feb 13, 2011 at 7:54 AM, andyturk \<andyt…\> wrote:\> \> In a traditional ACID database, when an error occurs inside a\> \> transaction, any updates made previously in the transaction are either\> \> rolled back or simply thrown away.\>\> \> I expected q’s table operations to behave the same way. However, this\> \> appears not to be the case. Consider the following example:\>\> \> KDB+ 2.7 2010.11.30 Copyright (C) 1993-2010 Kx Systems\> \> m32/ 2()core 4096MB andy mini.private 255.255.255.255 PLAY 2011.02.28\>\> \> q)t:( c1:`a`b`c; c2:10 20 30)&gt; &gt; q)@[`t;0;:;(`aa;99f)]&gt; &gt; 'type&gt; &gt; q)t&gt; &gt; c1 c2&gt; &gt; -----&gt; &gt; aa 10&gt; &gt; b ?20&gt; &gt; c ?30&gt;&gt; &gt; The partial update to the first column survives even though the&gt; &gt; overall call to @ fails. The same thing happens with direct&gt; &gt; assignment:&gt;&gt; &gt; q)t[0]:(`bb;98f)\> \> 'type\> \> q)t\> \> c1 c2\> \> -----\> \> bb 10\> \> b ?20\> \> c ?30\>\> \> Really?\>\> \> –\> \>

Submitted via Google Groups\</andyt…\>\</trie…\>

---

<div class="post-metadata">

**Author:** ![simon11](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@simon11](https://forum.kx.com/u/simon11)\
**Post date:** [February 16, 2011, 8:30am UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/4 "2011-02-16T08:30:00Z")

</div>

you don’t provide an example&nbsp;

but I’d guess you overlooked:

“Now update messages from clients are logged”

from the link Tim sent

using -l sets you up a server which has logging enabled for client&nbsp;messages&nbsp;

NOT for commands typed in at the console&nbsp;

try talking to your server from a client task, or for quick testing fooling it by using the handle 0

q)0"bb:17;aa:2 3+4 5 6"

rollback

'length

q)bb

'bb

q)aa

'aa

---

<div class="post-metadata">

**Author:** ![petrum1](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@petrum1](https://forum.kx.com/u/petrum1)\
**Post date:** [February 16, 2011, 2:01pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/5 "2011-02-16T14:01:00Z")

</div>

Thanks for reply.Here is an example:$\> q test -lKDB+ 2.7 2010.12.06 Copyright (C) 1993-2010 Kx Systems…q).z.f`testq)t:([] s:`a`b`c; i:1 2 3)q)\lq)ts i—a 1b 2c 3q)0 “t[0]:(`d;4f)"'typeq)ts i---d 1 \<= Did `d get into the table?!b 2c 3Regards,PMOn Feb 16, 3:30?am, Simon Garland \<si…\> wrote:\> you don’t provide an example\> but I’d guess you overlooked:\>\> “?Now update messages from clients are logged?”\>\> from the link Tim sent\>\> using -l sets you up a server which has logging enabled for client messages\> NOT for commands typed in at the console\> try talking to your server from a client task, or for quick testing fooling\> it by using the handle 0\>\> q)0"bb:17;aa:2 3+4 5 6”\> rollback\> 'length\> q)bb\> 'bb\> q)aa\> 'aa\>\> On 15 February 2011 23:15, petrum \<petru.margin…\> wrote:\>\> \> I’ve tried it, but I cannot get it to automatically rollback, and get\> \> the initial table when the update fails.\> \> The original data is restored (from logs) only if I restart the q\> \> process.\>\>\</petru.margin…\>\</si…\>

---

<div class="post-metadata">

**Author:** ![Lou](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Lou](https://forum.kx.com/u/Lou)\
**Post date:** [February 16, 2011, 5:34pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/6 "2011-02-16T17:34:00Z")

</div>

PM

?

try…

?

q)0 “t[0]:(`d;4 **i** )”

?

i think you’re getting a 'type error because the list is “i-\>integer” and you’re using “f-\>floating”

---

<div class="post-metadata">

**Author:** ![petrum1](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@petrum1](https://forum.kx.com/u/petrum1)\
**Post date:** [February 16, 2011, 6:26pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/7 "2011-02-16T18:26:00Z")

</div>

Agreed.But the problem is not why I get the 'type error (this wasintentionally generated), but why the “s” column gets updated (gettingthe `d in the first row).(please read the initial question in this thread, and the subject...)The expectation is that the update will rollback, and no column getsupdated.PMOn Feb 16, 12:34?pm, Louis Mercorelli <louis.mercore...>wrote:&gt; PM&gt;&gt; try...&gt;&gt; q)0 "t[0]:(`d;4_i_)"\>\> i think you’re getting a 'type error because the list is “i-\>integer” and\> you’re using “f-\>floating”\>\> On Thu, Feb 17, 2011 at 1:01 AM, petrum \<petru.margin…\> wrote:\> \> Thanks for reply.\> \> Here is an example:\>\> \> $\> q test -l\> \> KDB+ 2.7 2010.12.06 Copyright (C) 1993-2010 Kx Systems\> \> …\>\> \> q).z.f\> \> `test&gt; &gt; q)t:([] s:`a`b`c; i:1 2 3)\> \> q)\l\> \> q)t\> \> s i\> \> —\> \> a 1\> \> b 2\> \> c 3\> \> q)0 “t[0]:(`d;4f)"&gt; &gt; 'type&gt; &gt; q)t&gt; &gt; s i&gt; &gt; ---&gt; &gt; d 1 &lt;= Did `d get into the table?!\> \> b 2\> \> c 3\>\> \> Regards,\> \> PM\>\> \> On Feb 16, 3:30 am, Simon Garland \<si…\> wrote:\> \> \> you don’t provide an example\> \> \> but I’d guess you overlooked:\>\> \> \> “?Now update messages from clients are logged?”\>\> \> \> from the link Tim sent\>\> \> \> using -l sets you up a server which has logging enabled for client\> \> messages\> \> \> NOT for commands typed in at the console\> \> \> try talking to your server from a client task, or for quick testing\> \> fooling\> \> \> it by using the handle 0\>\> \> \> q)0"bb:17;aa:2 3+4 5 6”\> \> \> rollback\> \> \> 'length\> \> \> q)bb\> \> \> 'bb\> \> \> q)aa\> \> \> 'aa\>\> \> ?\> On 15 February 2011 23:15, petrum \<petru.margin…\> wrote:\>\> \> \> \> I’ve tried it, but I cannot get it to automatically rollback, and get\> \> \> \> the initial table when the update fails.\> \> \> \> The original data is restored (from logs) only if I restart the q\> \> \> \> process.\>\> \> –\> \>

Submitted via Google Groups\</petru.margin…\>\</si…\>\</petru.margin…\>\</louis.mercore…\>

---

<div class="post-metadata">

**Author:** ![Lou](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Lou](https://forum.kx.com/u/Lou)\
**Post date:** [February 16, 2011, 8:19pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/8 "2011-02-16T20:19:00Z")

</div>

oops, my first post to a group. sorry for the mistake.

?

LRM

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [February 16, 2011, 8:46pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/9 "2011-02-16T20:46:00Z")

</div>

fixed in next release. Thanks for bringing it to our attention.

$q -l log

KDB+ 2.7 2011.02.16 …

q)0"t:( s:`a`b`c; i:1 2 3)"

q)0"t[0]:(`d;4f)"

rollback

'type

q)t

s i

* * *

a 1

b 2

c 3

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [February 16, 2011, 9:17pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/10 "2011-02-16T21:17:00Z")

</div>

btw, a new release is available as 2.7 2011.02.16

---

<div class="post-metadata">

**Author:** ![petrum1](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@petrum1](https://forum.kx.com/u/petrum1)\
**Post date:** [February 17, 2011, 5:38pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/11 "2011-02-17T17:38:00Z")

</div>

What’s the meaning of the ‘log’ parameter in the prev. example?It looks like the ‘log’ param has to be before the “-l” flag,otherwise it seems to be ignored:C:\q\>w32\q.exe log -lKDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systemsw32/ …q).z.f`logC:\q\>w32\q.exe -l logKDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systemsw32/ ...q).z.f`Regards,PetruOn Feb 16, 3:46?pm, Charles Skelton \<char…\> wrote:\> fixed in next release. Thanks for bringing it to our attention.\>\> $q -l log\> KDB+ 2.7 2011.02.16 …\>\> q)0"t:( s:`a`b`c; i:1 2 3)"&gt; q)0"t[0]:(`d;4f)“\> rollback\> 'type\> q)t\> s i\> —\> a 1\> b 2\> c 3\>\> On Wed, Feb 16, 2011 at 7:26 PM, petrum \<petru.margin…\> wrote:\> \> Agreed.\>\> \> But the problem is not why I get the 'type error (this was\> \> intentionally generated), but why the “s” column gets updated (getting\> \> the `d in the first row).&gt; &gt; (please read the initial question in this thread, and the subject...)&gt;&gt; &gt; The expectation is that the update will rollback, and no column gets&gt; &gt; updated.&gt;&gt; &gt; PM&gt;&gt; &gt; On Feb 16, 12:34 pm, Louis Mercorelli <louis.mercore...>&gt; &gt; wrote:&gt; &gt; &gt; PM&gt;&gt; &gt; &gt; try...&gt;&gt; &gt; &gt; q)0 "t[0]:(`d;4_i_)”\>\> \> \> i think you’re getting a 'type error because the list is “i-\>integer” and\> \> \> you’re using “f-\>floating”\>\> \> \> On Thu, Feb 17, 2011 at 1:01 AM, petrum \<petru.margin…\>\> \> wrote:\> \> \> \> Thanks for reply.\> \> \> \> Here is an example:\>\> \> \> \> $\> q test -l\> \> \> \> KDB+ 2.7 2010.12.06 Copyright (C) 1993-2010 Kx Systems\> \> \> \> …\>\> \> \> \> q).z.f\> \> \> \> `test&gt; &gt; &gt; &gt; q)t:([] s:`a`b`c; i:1 2 3)\> \> \> \> q)\l\> \> \> \> q)t\> \> \> \> s i\> \> \> \> —\> \> \> \> a 1\> \> \> \> b 2\> \> \> \> c 3\> \> \> \> q)0 “t[0]:(`d;4f)"&gt; &gt; &gt; &gt; 'type&gt; &gt; &gt; &gt; q)t&gt; &gt; &gt; &gt; s i&gt; &gt; &gt; &gt; ---&gt; &gt; &gt; &gt; d 1 &lt;= Did `d get into the table?!\> \> \> \> b 2\> \> \> \> c 3\>\> \> \> \> Regards,\> \> \> \> PM\>\> \> \> \> On Feb 16, 3:30 am, Simon Garland \<si…\> wrote:\> \> \> \> \> you don’t provide an example\> \> \> \> \> but I’d guess you overlooked:\>\> \> \> \> \> “?Now update messages from clients are logged?”\>\> \> \> \> \> from the link Tim sent\>\> \> \> \> \> using -l sets you up a server which has logging enabled for client\> \> \> \> messages\> \> \> \> \> NOT for commands typed in at the console\> \> \> \> \> try talking to your server from a client task, or for quick testing\> \> \> \> fooling\> \> \> \> \> it by using the handle 0\>\> \> \> \> \> q)0"bb:17;aa:2 3+4 5 6”\> \> \> \> \> rollback\> \> \> \> \> 'length\> \> \> \> \> q)bb\> \> \> \> \> 'bb\> \> \> \> \> q)aa\> \> \> \> \> 'aa\>\> \> \> \> ?\> On 15 February 2011 23:15, petrum \<petru.margin…\>\> \> wrote:\>\> \> \> \> \> \> I’ve tried it, but I cannot get it to automatically rollback, and\> \> get\> \> \> \> \> \> the initial table when the update fails.\> \> \> \> \> \> The original data is restored (from logs) only if I restart the q\> \> \> \> \> \> process.\>\> \> \> \> –\> \> \> \> You received this message because you are subscribed to the Google\> \> Groups\> \> \> \> “Kdb+ Personal Developers” group.\> \> \> \> To post to this group, send email to [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)\> \> .\> \> \> \> To unsubscribe from this group, send email to\> \> \> \> [personal-kdbplus+unsubscribe@googlegroups.com](mailto:personal-kdbplus+unsubscribe@googlegroups.com).\> \> \> \> For more options, visit this group at\> \> \> \>[http://groups.google.com/group/personal-kdbplus?hl=en.&gt;&gt](http://groups.google.com/group/personal-kdbplus?hl=en.&gt;&gt); \> –\> \>

Submitted via Google Groups\</petru.margin…\>\</si…\>\</petru.margin…\>\</louis.mercore…\>\</petru.margin…\>\</char…\>

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [February 17, 2011, 5:48pm UTC](https://forum.kx.com/t/are-table-operations-atomic/6984/12 "2011-02-17T17:48:00Z")

</div>

yes, typo.

sorry.

https://code.kx.com/trac/wiki/Cookbook/Logging
