Page 1 of 1

postgres sequence problems

Posted: 29 Oct 2007, 20:51
by grafman
Getting this error when I submit a new bug:

currval of sequence "mantis_email_table_id_seq" is not yet defined in this session for the query:

I can run an insert from the psql command line and it works fine. I tried nextval but even though the insert worked the whole process didn't work because the tie in inserts like the text field custom field inserts didn't find the correct id number because they are calling currval as well so the keys are off.

I'm on Redhat SE 4, postres 8.2.4, PHP Version => 5.2.3, mantis version 1.1.0a4

The same version works great on mysql. I'm under constraints to use postgres. Any help would be greatly appreciated.

Re: Postgres Sequence Problems

Posted: 31 Oct 2007, 01:48
by SeniorDingDong
I had the same problem. My fix was probably quite a bit more than was necessary, and I think the root of it is that the column name of the email table is "email_id" rather than "id."

There is a function in database_api.php called

db_insert_id($p_table = null)

which i changed to

db_insert_id($p_table = null,$p_column = "id")

and changed the query string to

$query = "SELECT currval('" . $p_table . "_" . $p_column . "_seq')";

and then also changed the call to that function email_queue_api.php line 107 to

return db_insert_id( $t_email_table, "email_id" );

Posted: 31 Oct 2007, 04:40
by grafman
Thank you for the reply and the fix. I'll try it out ASAP.

Posted: 01 Nov 2007, 16:19
by grafman
You are wonderful! worked like a charm. I owe you a lunch sometime.

Re: postgres sequence problems

Posted: 08 Nov 2007, 06:52
by vboctor
The fix looks good. I've added a link to this thread from:
http://www.mantisbt.org/bugs/view.php?id=7616

I've sent a message to paulr (currently looking after pgsql) to apply the fix and validate it.