Thread: rows modified in current transaction
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hi,</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br /></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">isthere any wayto check if row have already been modified by the current transaction? I tried condition txid_current() = xmin, but thereis problem with the savepoints. After every savepoint rows are getting higher xmin values, but txid_current() remainsthe same.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br /></div><divstyle="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> Regards,</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Miroslav Simulcik</div>
On Thu, Aug 30, 2012 at 10:36 AM, Miroslav Šimulčík <simulcik.miro@gmail.com> wrote: > is there any way to check if row have already been modified by the current > transaction? I tried condition txid_current() = xmin, but there is problem > with the savepoints. After every savepoint rows are getting higher xmin > values, but txid_current() remains the same. It sounds like you're looking for a function that will give an array of all XIDs for the current transcation, rather than just the XID of the current sub-transaction. I don't think we currently expose that. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
On Thursday, August 30, 2012 06:06:59 PM Robert Haas wrote: > On Thu, Aug 30, 2012 at 10:36 AM, Miroslav Šimulčík > > <simulcik.miro@gmail.com> wrote: > > is there any way to check if row have already been modified by the > > current transaction? I tried condition txid_current() = xmin, but there > > is problem with the savepoints. After every savepoint rows are getting > > higher xmin values, but txid_current() remains the same. > > It sounds like you're looking for a function that will give an array > of all XIDs for the current transcation, rather than just the XID of > the current sub-transaction. I don't think we currently expose that. txid_current_snapshot(), txis_visible_in_snapshot() may work. Greetings, Andres -- Andres Freund http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services
Robert Haas <robertmhaas@gmail.com> writes: > On Thu, Aug 30, 2012 at 10:36 AM, Miroslav Šimulčík > <simulcik.miro@gmail.com> wrote: >> is there any way to check if row have already been modified by the current >> transaction? I tried condition txid_current() = xmin, but there is problem >> with the savepoints. After every savepoint rows are getting higher xmin >> values, but txid_current() remains the same. > It sounds like you're looking for a function that will give an array > of all XIDs for the current transcation, rather than just the XID of > the current sub-transaction. I don't think we currently expose that. IIRC, txid_current() actually reflects the current *top* transaction, which is why rows inserted by subtransactions aren't matching it. But yeah, there's no exported way to identify all the XIDs belonging to the current transaction. A larger problem with the above is that txid isn't an XID anyway, so the comparisons would fail altogether once the XID epoch becomes more than zero. So if we did want to support this, it would be a lot more useful to provide something along the lines ofxid_belongs_to_current_transaction(xid) returns bool than to expose the XIDs as such. regards, tom lane
On Thursday, August 30, 2012 06:09:43 PM Andres Freund wrote: > On Thursday, August 30, 2012 06:06:59 PM Robert Haas wrote: > > On Thu, Aug 30, 2012 at 10:36 AM, Miroslav Šimulčík > > > > <simulcik.miro@gmail.com> wrote: > > > is there any way to check if row have already been modified by the > > > current transaction? I tried condition txid_current() = xmin, but there > > > is problem with the savepoints. After every savepoint rows are getting > > > higher xmin values, but txid_current() remains the same. > > > > It sounds like you're looking for a function that will give an array > > of all XIDs for the current transcation, rather than just the XID of > > the current sub-transaction. I don't think we currently expose that. > > txid_current_snapshot(), txis_visible_in_snapshot() may work. No, it obviously cannot. No idea what I thought... txid_visible_in_snapshot is fine, but txid_current_snapshot() obviously will return a snapshot containing that sees everything the current transaction does. You possibly could calculate a difference between a txid_current_snapshot() taken at the beginning of a repeatable read transaction and the current one, but thats too ugly. Andres -- Andres Freund http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services