This is actually a Tcl quoting question: Since you provided the SQL query between double quotes ("), Tcl applies substitution, finds something that looks like a Tcl command via command substitution and tries to execute the command 0-9.
In case, you do not want Tcl substitution, use curly braces like here:
db_0or1row select_revision {
SELECT cr.title,
MAX(o.creation_date) AS creation_date,
COUNT(*) AS occurrence
FROM cr_items ci, cr_revisionsx cr, acs_objects o
WHERE ci.item_id = cr.item_id
AND ci.item_id = o.object_id AND ci.content_type = 'qt_vehicle'
AND cr.title !~ '^[0-9]'
AND cr.title NOT IN ('UNKNOWN', 'FBF724','FBF124')
GROUP BY cr.title HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
}
In general, Tcl substitutions should be avoided in SQL statements (or applied with special care), since these are potential attack vectors for SQL injection. Bind variables should be used instead wherever possible.
-g
PS: the markup character for code is for markdown a backtick (`) not a single quote (').