title: Psycopg2 "Can't execute an empty query"
body: <p>I saved some queries in a single <em>.sql</em> script, instead of writing them directly inside variables in a <em>.py</em> script.</p>
  
  <p>Now I want to read this sql script using Python, split each sql statement by semicolon and then pass each of these scripts to Psycopg2 cursor for sequential execution.</p>
  
  <p>The python script seems to read the file correctly, but a "can't execute an empty query" error is thrown when I try to execute the statements.</p>
  
  <p>Maybe the catch is: there are many line-breaks spread across this sql script. Statements in it are written like below:</p>
  
  <pre><code>DROP TABLE IF EXISTS
      target_schema.some_table
  ;
  
  SELECT
      column
  FROM
      schema.table
  ;
  
  </code></pre>
  
  <p>Here's the python code:</p>
  
  <pre><code>import psycopg2
  import pathlib
  
  conn = psycopg2.connect(
       user=user
      ,password=password
      ,host=host
      ,port=port
      ,database=database
  )
  
  pg_cursor = conn.cursor()
  
  scriptContents = Path('my_folder\my_sql_script.sql').read_text(encoding='utf-8')
  
  sqlStatements = scriptContents.split(sep=';')
  
  for statement in sqlStatements:    
  
      try:
          pg_cursor.execute(f'{statement}')
          conn.commit()
      except psycopg2.Error as errorMsg:
          print(errorMsg)        
          conn.rollback()
  </code></pre>
  
  <p>Could anyone help me solve this?</p>