Re: How to mark a transaction as SERIALIZABLE?

From: Thom Brown <thom(at)linux(dot)com>
To: Joe Carr <joe(dot)carr(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How to mark a transaction as SERIALIZABLE?
Date: 2010-11-02 09:13:49
Message-ID: AANLkTikTkv5nJ5ZwZMN4LEkYWcWEY-oP6CYEz=jDtMkn@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 2 November 2010 01:51, Joe Carr <joe(dot)carr(at)gmail(dot)com> wrote:

> In version 9.0, I've been reading
> http://www.postgresql.org/docs/9.0/interactive/sql-begin.html. I've been
> using the following :
>
> CREATE OR REPLACE FUNCTION test(character varying)
> RETURNS SETOF integer AS
> $BODY$
>
> BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> --SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> RETURN 1;
> END;
> $BODY$
> LANGUAGE plpgsql VOLATILE
>
> which returns with the error :
> ERROR: syntax error at or near "TRANSACTION"
> LINE 1: TRANSACTION ISOLATION LEVEL SERIALIZABLE
>
> if the BEGIN line is empty with no semi-colon, the function will work :
> CREATE OR REPLACE FUNCTION test(character varying)
> RETURNS integer AS
> $BODY$
>
> BEGIN
> --TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> --SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
>
> RETURN 1;
> END;
> $BODY$
> LANGUAGE plpgsql VOLATILE
>
> but if I place a semi-colon after BEGIN (e.g. BEGIN;), I get the error :
> ERROR: syntax error at or near ";"
> LINE 5: BEGIN;
>
> So any help you may be able to provide in the BEGIN syntax (or whatever I'm
> doing wrong) is greatly appreciated. Thanks!
>
> -Joe
>
>
BEGIN in your function isn't the same as BEGIN in an SQL statement block.
It merely marks where the function begins, not the transaction. Note that
you also shouldn't use a semi-colon after the BEGIN in a function. See this
page for more info:
http://www.postgresql.org/docs/9.0/interactive/plpgsql-structure.html

--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Joe Carr 2010-11-02 13:24:02 Re: How to mark a transaction as SERIALIZABLE?
Previous Message Yogesh Sharma 2010-11-02 05:09:24 Re: SELECT triggers - Table Partitioning