The issue appears to be with the custom SQL query being used. Can you run the query against your Redshift cluster using any IDE or Redshift query editor and check if the error persists? If so, the query has to be modified.
Please let us know if the query works without any issues in your IDE/query editor.
Thank you for letting us know. I would recommend filing a case with AWS Support where we can dive into the details so that we can help you further. Here are the steps to open a support case. If your company has someone who manages your AWS account, you might not have direct access to AWS Support and will need to raise an internal ticket to your IT team or whomever manages your AWS account. They should be able to open an AWS Support case on your behalf. Hope this helps!