Re: Bit by "commands ignored until end of transaction block" again

From: Chris <dmagick(at)gmail(dot)com>
To: Joshua Tolley <eggyknap(at)gmail(dot)com>
Cc: Glenn Maynard <glenn(at)zewt(dot)org>, Richard Huxton <dev(at)archonet(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Bit by "commands ignored until end of transaction block" again
Date: 2009-07-23 07:06:43
Message-ID: 4A680C03.6040701@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Joshua Tolley wrote:
> On Thu, Jul 23, 2009 at 02:04:53AM -0400, Glenn Maynard wrote:
>> On Thu, Jul 23, 2009 at 1:31 AM, Richard Huxton<dev(at)archonet(dot)com> wrote:
>>>> - Let me use SAVEPOINT outside of a transaction,
>>> You are never outside a transaction. All queries are executed within a
>>> transaction.
>> "Transaction block", then, if you insist.
>>
>>> I think this is the root of your problem - all queries are within a
>>> transaction so either:
>>> 1. You have a transaction that wraps a single statement. If you get an error
>>> then only that statement was affected.
>>> 2. You have an explicit BEGIN...COMMIT transaction which could use a
>>> savepoint.
>> Savepoints can only be used inside transaction blocks. My function
>> has no idea whether it's being called inside a transaction block.
>>
>> From inside a transaction block, my function would need to call
>> SAVEPOINT/RELEASE SAVEPOINT.
>>
>> If it's not in a transaction block, it needs to call BEGIN/COMMIT
>> instead. SAVEPOINT will fail with "SAVEPOINT can only be used in
>> transaction blocks".
>
> Have you tried this? I expect if you give it a shot, you'll find you don't
> actually have this problem. Really, everything is always in a transaction.

Each statement is in it's own transaction, but the problem (as I
understand it) is that you're in this sort of situation:

psql -d dbname
..
# select now();
now
-------------------------------
2009-07-23 17:04:21.406424+10
(1 row)

Time: 2.434 ms
(csmith(at)[local]:5432) 17:04:21 [test]
# savepoint xyz;
ERROR: SAVEPOINT can only be used in transaction blocks
(csmith(at)[local]:5432) 17:04:25 [test]

You haven't explicitly started a transaction, therefore savepoints won't
work.

Django (it seems) just issues queries with no knowledge of (and no way
to support) them.

--
Postgresql & php tutorials
http://www.designmagick.com/

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2009-07-23 07:10:08 Re: Need magical advice for counting NOTHING
Previous Message A. Kretschmer 2009-07-23 06:57:22 Re: Need magical advice for counting NOTHING