my pl/pgsql functions return weird results

Поиск
Список
Период
Сортировка
Искать
От
Olivier Garcia
Тема
my pl/pgsql functions return weird results
Дата
Msg-id
1014365248.20427.6.camel@sauron
Ответ на
Список
Дерево обсуждения
Full bug list "Andy Marden" <amarden@usa.net>
Re: Full bug list Justin <aa2@bigpond.net.au>
my pl/pgsql functions return weird results Olivier Garcia <ogarcia@waidan.com>
Re: my pl/pgsql functions return weird results Tom Lane <tgl@sss.pgh.pa.us>
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
Дата:
От: pgsql-bugs@postgresql.org
Дата:
FAQ