title: Using DELETE FROM...RETURNING in a PostgreSQL IF / THEN Statement
body: <p>I have this code:</p>
  <pre><code>DO $$
  returns table (msg varchar(500), isSuccessful BIT) as $BODY$
  declare
  newID integer := null;
  id integer := 100;
  BEGIN
  IF newID is NULL 
  then delete from table1 t1 where t1.id = id;
  delete from table2 t2 where t2.id = id
  returning 'test' as msg, 1 as isSuccessful;
  else insert into table1(id, name)
  values(id, 'testname');
  END IF;
  END $$; 
  </code></pre>
  <p>When I run this, I'm getting this error:</p>
  <p><em>ERROR: syntax error at or near &quot;returns&quot;</em></p>
  <p>I originally didn't have the <code>returns table</code>  line, but after some research it's my understanding that I need to establish a table for the data in the <code>returning</code> line to write into.</p>
  <p>What I want to return is the following:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>msg</th>
  <th>isSuccessful</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>test</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>What am I doing wrong with my <code>returns table</code> line and how do I achieve the output I'm looking for? Also, do I have to create a function in order for this to work?</p>