my pl/pgsql functions return weird results

Поиск
Список
Период
Сортировка
От Olivier Garcia
Тема my pl/pgsql functions return weird results
Дата
Msg-id 1014365248.20427.6.camel@sauron
обсуждение исходный текст
Ответ на Re: Full bug list  (Justin <aa2@bigpond.net.au>)
Ответы Re: my pl/pgsql functions return weird results  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
Hi!

My base contains a table objectid

create table objectid(
    next bigint
);

INSERT INTO objectid values(1);

I do really need to use this table like if it was a sequence so I made
some pl/pgsql functions ( functions at the end of the mail ).
But when I run them in three psql at the same time the results are
weird... Here are the results :

psql1: 2 ( ok )
psql2: 1 ( instead of 3 )
psql3: 1 ( instead of 4 )

Scary...

and after that, a "select * from objectid;" returns 4 ( that's ok ).

I'm using pgsql 7.1.3 ( debian package 7.1.3-8 on a 2.4.17 kernel )

-----------------------------
----------- Functions
-----------------------------

drop table objectid;

create table objectid(
    next bigint
);

INSERT INTO objectid values(1);

drop function next_objectid();

create function next_objectid() returns bigint as '
DECLARE
   o RECORD;
   a integer;
BEGIN
   raise notice ''before lock'';
   lock table objectid in access exclusive mode;
   raise notice ''locked, before pause'';
   a := pause(1000000);
   raise notice ''pause finished, updating'';
   update objectid set next=next+1;
   select into o next from objectid;
   raise notice ''returning'';
   return o.next;
END;
' language 'plpgsql';

drop function pause(int);

create function pause(int) returns int as '
DECLARE
   i integer;
   j integer;
BEGIN
   FOR i IN 1 .. $1 LOOP
      j := i+1;
   end loop;
   return j;
END;
' language 'plpgsql';

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Justin Clift
Дата:
Сообщение: Re: Trying Cygwin version of PostgreSQL again
Следующее
От: pgsql-bugs@postgresql.org
Дата:
Сообщение: Bug #600: how to run the Postgres postmaster with -i flag