title: batch file to store the psql query output into a variable
body: <p>Hi I am creating a batch file to execute a query and write a log file for the output. So based on some condition the there two queries to be executed.
  So I was trying to store a output value of a query in to a variable and use that variable value to check the condition.
  But here I am facing a problem that how should I suppose to declare and store output value into a variable using psql command.
  Please help!! 
  Here what I tried:</p>
  
  <pre><code>SET /A a = psql -t -U postgres -d rpd -c "select count(*) from rpd.rpm_rpd_count"
  SET /A b = 1
  
  if %a% == 3 goto is_stat 
  else goto is_start
  
  REM to copy the log
  :is_start  
  psql -U postgres -d rpd -c "SELECT
  a.table_name , 'MATCH' status  FROM rpd.rpm_rpd_count A  WHERE
  a.rpd_count = a.rpm_count UNION ALL SELECT a.table_name, 'NOT MATCH'
  AS status FROM rpd.rpm_rpd_count A WHERE a.rpd_count &lt;&gt;  a.rpm_count;" &gt;&gt; C:\Users\admin\Desktop\err.log
  goto END
  :is_stat 
  psql -U postgres -d rpd -c "SELECT a.table_name , 'MATCH'
  status  FROM rpd.rpm_rpd_count A  WHERE a.rpd_count = a.rpm_count;" &gt;&gt;
  C:\Users\admin\Desktop\err.log 
  goto END
  :END 
  echo %b% &gt;&gt; C:\Users\admin\Desktop\err.log
  </code></pre>
  
  <p>Problem here is that nothing is getting saved in the variable <strong>a</strong></p>