View Issue Details

This issue affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
20640Bug reportsDatabase designpublic2026-08-31 20:49
Reporterthegcat Assigned Toc_schmitz  
PrioritynoneSeverityblock 
Status closedResolutionfixed 
Product Version7.0.x 
Summary20640: "error saving results" on surveys active before update to LS 7 on PostgreSQL
Description

Trying to take a survey that was already active before the update to LimeSurvey 7 and that has already received answers is currently not possible with PostgreSQL. Trying to take the survey shows an "error saving results" error and sends the responses to the administrator via e-mail. This error appears at the very beginning of the flow, not when trying to finish the survey.

Furthermore, the following SQL error is recorded:

SQL CODE THAT FAILED:
CDbCommand failed to execute the SQL statement: SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "lime_responses_872275_pkey"
DETAIL: Key (id)=(3) already exists.

We have identified a probable cause, see the next comment.

TagsNo tags attached.
Bug heat8
Complete LimeSurvey version number (& build)7.0.7-260729
I will donate to the project if issue is resolvedNo
Browser
Database type & versionPostgreSQL 18.4
Server OS (if known)
Webserver software & version (if known)
PHP Version8.5.9

Users monitoring this issue

lavamind

Activities

thegcat

thegcat

2026-08-06 21:00

reporter   ~85384

During the update from LimeSurvey 6.x to 7.0 it seems the tables lime_survey_123456 (we think this is what they were called before) have been renamed to lime_responses_123456 . Unfortunately this did not migrate the lime_survey_123456_id_seq sequence value to lime_responses_123456_seq_id, thus causing LimeSurvey to try to save new responses at ID 1, then 2, then 3 and so on although those ID slots are already filled.

thegcat

thegcat

2026-08-06 23:56

reporter   ~85385

So the easiest path out of this is setting the _seq_id to the highest ID of the corresponding table. The idiomatic PostgreSQL for this would be:

ALTER SEQUENCE lime_responses_123456_seq_id RESTART WITH 235;

This requires calculating the next free ID beforehand and would probably need to be wrapped in a lock to guarantee no insertions in the table between reading the next free ID and altering the sequence.

The other solution could be to use an "all in one" query like:

SELECT setval('lime_responses_123456_id_seq'::regclass, (SELECT MAX(ID) FROM lime_responses_123456));

setval has no concurrency guarantees though so it should probably only be run in this form in an environment with exclusive access, for example in a database migration.

thegcat

thegcat

2026-08-06 23:58

reporter   ~85386

I am also not sure if other tables might be affected by this issue, I hope the core developers can assess this.

c_schmitz

c_schmitz

2026-08-10 10:24

administrator   ~85410

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=40128

LimeBot

LimeBot

2026-08-11 16:01

administrator   ~85427

Fixed in Release 7.0.9+260812

LimeBot

LimeBot

2026-08-11 16:01

administrator   ~85436

Fixed in Release 7.0.9+260812

Related Changesets

LimeSurvey: master ec53b4bb

2026-08-10 10:24

c_schmitz

Committer: GitHub


Details Diff
Fixed issue 20640: "Error saving results" on surveys active before update to version 7 on PostgreSQL (05214) Affected Issues
20640
mod - application/config/version.php Diff File
mod - application/helpers/update/updatedb_helper.php Diff File
mod - application/helpers/update/updates/Update_700.php Diff File
add - application/helpers/update/updates/Update_710.php Diff File

Issue History

Date Modified Username Field Change
2026-08-06 20:53 thegcat New Issue
2026-08-06 21:00 thegcat Note Added: 85384
2026-08-06 21:00 thegcat Bug heat 0 => 2
2026-08-06 23:56 thegcat Note Added: 85385
2026-08-06 23:58 thegcat Note Added: 85386
2026-08-07 10:21 c_schmitz Assigned To => c_schmitz
2026-08-07 10:21 c_schmitz Status new => ready for code review
2026-08-10 10:24 c_schmitz Changeset attached => LimeSurvey master ec53b4bb
2026-08-10 10:24 c_schmitz Note Added: 85410
2026-08-10 10:24 c_schmitz Status ready for code review => resolved
2026-08-10 10:24 c_schmitz Resolution open => fixed
2026-08-10 10:24 c_schmitz Bug heat 2 => 4
2026-08-11 16:01 LimeBot Note Added: 85427
2026-08-11 16:01 LimeBot Status resolved => closed
2026-08-11 16:01 LimeBot Bug heat 4 => 6
2026-08-11 16:01 LimeBot Note Added: 85436
2026-08-31 20:49 lavamind Issue Monitored: lavamind
2026-08-31 20:49 lavamind Bug heat 6 => 8