title: INSERT and RETURNING multiple values SQL
body: <p>I have two tables where relationship one to many, and I want INSERT to <code>mytable</code> some values and RETURNING multiple values INTO variables to use them later. Here example:</p>
  <pre><code> IF NOT EXISTS
          (SELECT id FROM mytable WHERE label_id = xxx)
      THEN
          INSERT INTO mytable
          (label_id, &quot;name&quot;)
          VALUES
          (xxx,'foo'),
          (xxx,'bar')
      RETURNING 
          (SELECT id INTO mytable_id1 FROM mytable WHERE name = 'foo'),
          (SELECT id INTO mytable_id2 FROM mytable WHERE name = 'bar');
      ELSE 
          (SELECT id INTO mytable_id1 FROM mytable WHERE name = 'foo'),
          (SELECT id INTO mytable_id2 FROM mytable WHERE name = 'bar');
   END IF;
  </code></pre>
  <p>But I get always error:</p>
  <blockquote>
  <p>ERROR: INTO specified more than once at or near &quot;into&quot;</p>
  </blockquote>
  <p>I trying google problem and for example <a href="https://stackoverflow.com/questions/20508387/insert-into-returning-multiple-columns-postgresql">INSERT INTO ... RETURNING multiple columns (PostgreSQL)</a> and <a href="https://stackoverflow.com/questions/18803586/error-into-specified-more-than-once-at-or-near-into">Error: INTO specified more than once at or near &quot;INTO&quot;</a></p>
  <p>unfortunately solutions it doesn't help for me (or I do something wrong). Any ideas?</p>