title: Escaping quotes in Redshift query
body: <p><br>
  I am trying to refactor my code to PEP8 standards for readability but I'm struggling to escape quotes in my SQL queries.
  I have 2 queries. The first is a simple SQL query. The second is a Redshift UNLOAD command.</p>
  
  <pre><code>query = '''SELECT * FROM redshift_table
             LEFT JOIN
             (SELECT DISTINCT * FROM redshift_view) v
             ON redshift_table.account_number = v.card_no
             WHERE timestamp &lt; date_trunc('day', CURRENT_DATE)
             AND timestamp &gt;=  (CURRENT_DATE - INTERVAL '1 days')'''
  
  unload = '''UNLOAD ('%s') to '%s'
              credentials 'aws_access_key_id=%s;aws_secret_access_key=%s'
              delimiter as '%s'parallel off ALLOWOVERWRITE''' % (query, s3_path, access_key, aws_secret, file_delimiter)
  </code></pre>
  
  <p>Because the sql query is imbedded inside the UNLOAD command, I can only make it work by escaping quotes by prepending them with 3 backslashes: 'day' becomes ///'day///'. <br>
  This isn't ideal and I was wondering if there was a way around it.</p>
  
  <p>Any help is greatly appreciated. Thank you.</p>