Another error I think releated to the same thing. When going to edit an existing post I get the following;
That's not quick edit that works correctly. It's also on postgresql.
To help here is the query before and after the preg_replace
Before
string(520) "
SELECT
m.subject, COALESCE(mem.real_name, m.poster_name) AS real_name, m.poster_time, m.body,
m.id_msg, m.smileys_enabled, m.id_member
FROM (
SELECT
m.id_msg
FROM {db_prefix}messages AS m
WHERE m.id_topic = {int:current_topic}
AND m.id_msg < {int:msg_before}
ORDER BY m.id_msg DESC
LIMIT {int:start}, {int:messages_per_page}) AS o
JOIN {db_prefix}messages as m ON o.id_msg=m.id_msg
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
ORDER BY m.id_msg DESC"
After
string(526) "
SELECT
m.subject, COALESCE(mem.real_name, m.poster_name) AS real_name, m.poster_time, m.body,
m.id_msg, m.smileys_enabled, m.id_member
FROM (
SELECT
m.id_msg
FROM {db_prefix}messages AS m
WHERE m.id_topic = {int:current_topic}
AND m.id_msg < {int:msg_before}
ORDER BY m.id_msg DESC
LIMIT {int:messages_per_page}) AS o
JOIN {db_prefix}messages as m ON o.id_msg=m.id_msg
LEFT JOIN {db_prefix} OFFSET {int:start} members AS mem ON (mem.id_member = m.id_member)
ORDER BY m.id_msg DESC"
The issue is your regex looks for the last } token, which in this case is the last db_prefix not the one on the same line. I'm not sure why the single line is being ignored.
Final edit:
Changing the s to a m seems to resolve the issue in this case.
$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*(.*)$~im', 'LIMIT $2 OFFSET $1 $3', $db_string);