postgres sequence problems

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
grafman
Posts: 4
Joined: 25 Oct 2007, 16:10

postgres sequence problems

Post 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.
SeniorDingDong
Posts: 1
Joined: 31 Oct 2007, 01:31
Contact:

Re: Postgres Sequence Problems

Post 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" );
grafman
Posts: 4
Joined: 25 Oct 2007, 16:10

Post by grafman »

Thank you for the reply and the fix. I'll try it out ASAP.
grafman
Posts: 4
Joined: 25 Oct 2007, 16:10

Post by grafman »

You are wonderful! worked like a charm. I owe you a lunch sometime.
vboctor
Site Admin
Posts: 1293
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Re: postgres sequence problems

Post 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.
Migrate your MantisBT to the MantisHub Cloud
Post Reply