Re: Err. compiling func. with SET TRANS...

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: <otisg(at)ivillage(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Err. compiling func. with SET TRANS...
Date: 2002-02-27 07:54:28
Message-ID: GNELIHDDFBOCMGBFGEFOCEJDCBAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> CREATE FUNCTION simple_fun() RETURNS INTEGER AS '
> BEGIN
> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> BEGIN;
> SELECT 1;
> END;
> RETURN 1;
> END;
> ' LANGUAGE 'plpgsql';
>
> This is as simple as it gets.
> I think my syntax is correct (I checked Practical PostgreSQL book
> as well as a number of 7.2 PDF documents, etc.).
>
> Am I missing a secret ingredient here?

I'm no PL/PgSQL expert, but I think that you cannot do transactions within a
function (this is because postgres doesn't support nested transactions.

However, since the function will run inside a transaction anyway, just do
this:

CREATE FUNCTION simple_fun() RETURNS INTEGER AS '
BEGIN
SELECT 1;
RETURN 1;
END;
' LANGUAGE 'plpgsql';

Now, of course you can't do your isolated transaction, so you'll need to
create the function above and then use it like this:

BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT simple_fun();
COMMIT;

Chris

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message D'Arcy J.M. Cain 2002-02-27 08:51:51 Re: INSERT requires SERIAL column?
Previous Message Christopher Kings-Lynne 2002-02-27 07:50:20 Re: INSERT requires SERIAL column?