I would like to change all SELECT COUNT(*)
queries with SELECT COUNT(1)
(for this use case).
I have the following lua script, but it does not work somehow:
function read_query( packet )
if string.byte(packet) == proxy.COM_QUERY then
local query = string.sub(packet, 2)
local replacing = false
if string.match(string.upper(query), 'COUNT(*)') then
query = string.gsub(query,'COUNT(*)', 'COUNT(1)')
replacing = true
end
if (replacing) then
proxy.queries:append(1, string.char(proxy.COM_QUERY) .. query )
return proxy.PROXY_SEND_QUERY
end
end
end
What am I doing wrong?