title: Redshift create table not working via Python
body: <p>As per <a href="https://stackoverflow.com/questions/48177244/unload-to-s3-with-python-using-iam-role-credentials">Unload to S3 with Python using IAM Role credentials</a>, the unload statement worked perfectly. So did other commands I tried, like copy and select statements. </p>
  
  <p>However, I also tried to run a query which creates a table.. The create table query runs without error, but when it gets to the select statement, it throws an errors that <code>relation "public.test" does not exist</code>. </p>
  
  <p>Any idea why is the table not created properly? Query below:</p>
  
  <pre><code>import sqlalchemy as sa
  from sqlalchemy.orm import sessionmaker
  import config
  import pandas as pd
  
  #&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; MAKE CHANGES HERE &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  DATABASE = "db"
  USER = "user"
  PASSWORD = getattr(config, 'password') #see answer by David Bern https://stackoverflow.com/questions/43136925/create-a-config-file-to-hold-values-like-username-password-url-in-python-behave/43137301
  HOST = "host"
  PORT = "5439"
  SCHEMA = "public"      #default is "public"
  
  ########## connection and session creation ##########
  connection_string = "redshift+psycopg2://%s:%s@%s:%s/%s" % (USER,PASSWORD,HOST,str(PORT),DATABASE)
  engine = sa.create_engine(connection_string)
  session = sessionmaker()
  session.configure(bind=engine)
  s = session()
  SetPath = "SET search_path TO %s" % SCHEMA
  s.execute(SetPath)
  
  --create table example
  query2 = '''\ 
  create table public.test (
  id integer encode lzo,
  user_id integer encode lzo,
  created_at timestamp encode delta32k,
  updated_at timestamp encode delta32k
  )
  distkey(id)
  sortkey(id)
  '''
  
  r2 = s.execute(query2)
  
  --select example
  query4 = '''\ 
  select * from public.test
  '''
  
  r4 = s.execute(query4)
  
  ########## create DataFrame from SQL query output ##########
  df = pd.read_sql_query(query4, connection_string)
  
  print(df.head(50))
  
  ########## close session in the end ##########
  s.close()
  </code></pre>
  
  <p>If I run the same directly in Redshift, it works just fine..</p>
  
  <p>--Edit--</p>
  
  <p>Some of the things tried:</p>
  
  <ul>
  <li><p>Removing "\" from query string</p></li>
  <li><p>adding ";" at the end of query string</p></li>
  <li><p>changing "public.test" to "test"</p></li>
  <li><p>removing SetPath = "SET search_path TO %s" % SCHEMA and s.execute(SetPath)</p></li>
  <li><p>breaking the create statement- generates expected error</p></li>
  <li><p>adding copy from S3 command after create- runs without error, but again no table created</p></li>
  <li><p>adding a column to create statement that doesnt exist in the file that is generated from the copy command- generates expected error</p></li>
  <li><p>adding r4 = s.execute(query4)- runs without error, but again created table not in Redshift</p></li>
  </ul>