Fixed sql functions