Current time: 03-22-2010, 01:07 AM Hello There, Guest! (LoginRegister)


"create new forum" generates postgresql error
07-02-2009, 08:48 PM
Post: #1
"create new forum" generates postgresql error
Using pgsql 8.3.7 on CentOS 5.3, on a brand new 1.4.8 test install...

Almost the very first thing I did after finishing the install was to go to Admin CP, Forums, and try and add a new forum, and get...

Code:
MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
    23505 - ERROR: duplicate key value violates unique constraint "mybb_forums_pkey"
Query:
    INSERT INTO mybb_forums (name,description,linkto,type,pid,parentlist,disporder,active,open,allowhtml,all​owmycode,allowsmilies,allowimgcode,allowpicons,allowtratings,usepostcounts,passw​ord,showinjump,modposts,modthreads,mod_edit_posts,modattachments,style,overrides​tyle,rulestype,rulestitle,rules,defaultdatecut,defaultsortby,defaultsortorder) VALUES ('Another Forum','testing a 2nd forum','','f','1','','2','1','1','0','1','1','1','1','1','1','','1','0','0','0',​'0','0','0','0','','','0','','')

I ran into this in my original (now live) forum... apparently the default category and forum were pre-created with a pkey of '1' and '2', but the sequence associated with the SERIAL "fid" was not advanced, so this first INSERT is trying to insert forum #1.

see...
Code:
mybbtest=# select fid,name from mybb_forums;
fid |    name    
-----+-------------
   1 | My Category
   2 | My Forum
(2 rows)

mybbtest=# select * from mybb_forums_fid_seq;
    sequence_name    | last_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called
---------------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
mybb_forums_fid_seq |          1 |            1 | 9223372036854775807 |         1 |           1 |      32 | f         | t

I'm guessing the 'fix' is to NOT hardcode the fid=1 and fid=2 for the default category/forum (eg, use DEFAULT, or don't insert the field at all), or to manually advance the sequence by invoking select nextval('mybb_forums_fid_seq'::regclass); twice.
Find all posts by this user
07-02-2009, 09:04 PM
Post: #2
RE: "create new forum" generates postgresql error
We don't hardcode fid=1 or fid=2 in the query - This looks like a PostgreSQL bug to me

[Image: ryangordon.png]
My Blog - My Mods
Visit this user's website Find all posts by this user
07-02-2009, 09:27 PM
Post: #3
RE: "create new forum" generates postgresql error
(07-02-2009 09:04 PM)Ryan Gordon Wrote:  We don't hardcode fid=1 or fid=2 in the query - This looks like a PostgreSQL bug to me

oh?

Code:
install/resources/mysql_db_inserts.php:$inserts[] = "INSERT INTO mybb_forums (fid, name, description, linkto, type, pid, parentlist, disporder, active, open, threads, posts, lastpost, lastposter, lastposttid, allowhtml, allowmycode, allowsmilies, allowimgcode, allowpicons, allowtratings, status, usepostcounts, password, showinjump, modposts, modthreads, modattachments, style, overridestyle, rulestype, rulestitle, rules) VALUES (1, 'My Category', '', '', 'c', 0, '1', 1, 1, 1, 0, 0, 0, '0', 0, 0, 1, 1, 1, 1, 1, 1, 1, '', 1, 0, 0, 0, 0, 0, 0, '', '');";
install/resources/mysql_db_inserts.php:$inserts[] = "INSERT INTO mybb_forums (fid, name, description, linkto, type, pid, parentlist, disporder, active, open, threads, posts, lastpost, lastposter, lastposttid, allowhtml, allowmycode, allowsmilies, allowimgcode, allowpicons, allowtratings, status, usepostcounts, password, showinjump, modposts, modthreads, modattachments, style, overridestyle, rulestype, rulestitle, rules) VALUES (2, 'My Forum', '', '', 'f', 1, '1,2', 1, 1, 1, 0, 0, 0, '0', 0, 0, 1, 1, 1, 1, 1, 1, 1, '', 1, 0, 0, 0, 0, 0, 0, '', '');";

looks hard coded to me ?
Find all posts by this user
07-02-2009, 09:33 PM
Post: #4
RE: "create new forum" generates postgresql error
Ah, you quoted a different query - I took that as the one you were talking about.

[Image: ryangordon.png]
My Blog - My Mods
Visit this user's website Find all posts by this user
07-02-2009, 09:55 PM
Post: #5
RE: "create new forum" generates postgresql error
yeah, sorry. i should have been clearer, what I meant was the original insertion queries bypassed the DEFAULT expression for the SERIAL, so the associated sequence didn't get advanced. this is a 'feature' of how pg's SERIAL is implemented (its just an integer field that has an associated sequence, and default nextval() expression....
Find all posts by this user
08-19-2009, 06:02 AM
Post: #6
RE: "create new forum" generates postgresql error
It should have something like:
Code:
update mybb_forums_fid_seq set last_value=2
at the end of the installation script.
Find all posts by this user
08-20-2009, 06:31 PM
Post: #7
RE: "create new forum" generates postgresql error
Corresponding ticket: http://dev.mybboard.net/issues/385

Greets,
Michael
-------------
German MyBB-Site
MyBBoard.de
Get the german languagepack here
Visit this user's website Find all posts by this user


Forum Jump: