title: Drop all tables in postgresql using bash script
body: <p>I am a novice bash script user. I am trying to execute this postgresql command (which outputs commands that drops tables whose name is like r_395)</p>
  
  <pre><code>SELECT 'DROP TABLE ' || tablename FROM pg_catalog.pg_tables where tablename like 'r_395%';
  </code></pre>
  
  <p>output of this query is:</p>
  
  <pre><code>?column?      
  --------------------
   DROP TABLE r_395_0
   DROP TABLE r_395_1
   DROP TABLE r_395_2
   DROP TABLE r_395_3
   DROP TABLE r_395_4
   DROP TABLE r_395_5
   DROP TABLE r_395_6
   DROP TABLE r_395_7
   DROP TABLE r_395_8
   DROP TABLE r_395_9
  (10 rows)
  </code></pre>
  
  <p>using bash with this command:  </p>
  
  <pre><code>/bin/su - postgres -c "/usr/bin/psql database -c SELECT 'DROP TABLE ' || tablename FROM pg_catalog.pg_tables where tablename like 'r_395%'" &gt; droptables
  </code></pre>
  
  <p>But I am getting this error:</p>
  
  <pre><code>psql: FATAL:  role "DROP TABLE " does not exist
  -bash: tablename: command not found
  </code></pre>
  
  <p>What am I doing wrong?</p>