I think you haven't counted your quotes correctly.
quote_literal() would probably help you build a valid ILIKE patternwith less pain.
regards, tom lane