title: Combine 2 variables inside postgres procedure
body: <p>I have 3 tables: post, tag, and tag_post</p>
  <p>post holds the actual posts, tags holds the tags that have been created so far and tag_post holds the relation between them.
  When a new post is created, 4 things happen:</p>
  <ul>
  <li><p>all tags that dont exist yet are created</p>
  </li>
  <li><p>the post is created</p>
  </li>
  <li><p>all the tag_post relations are created</p>
  </li>
  <li><p>the newly created post is returned to the function caller</p>
  </li>
  </ul>
  <p>These are the tables</p>
  <pre><code>/*
  POST TABLES
  */
  
  CREATE TABLE tag(
      name text PRIMARY KEY,
      check(name!='')
  );
  
  CREATE TABLE post(
      id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
      title text,
      url text,
      author text NOT NULL references profile(name)
  );
  
  CREATE TABLE tag_post(
      tag text REFERENCES tag(name),
      post uuid REFERENCES post(id),
      UNIQUE (tag, post)
  );
  </code></pre>
  <p>Heres how I did that:</p>
  <pre><code>/*
  CREATE A NEW POST
   */
   
  create or replace function create_post(
      author text,
      title text,
      url text,
      tags text[]
  
  )
  RETURNS post
  as $$
  DECLARE 
  inserted record;
  begin
  
      INSERT INTO tag(name)
      SELECT v
      FROM unnest(tags) g(v)
      ON CONFLICT DO NOTHING;
  
  
      INSERT INTO post(author, title, url) 
      values(author,title,url) 
      RETURNING * INTO inserted;
  
      INSERT INTO tag_post(tag,post)
      SELECT g.v, inserted.id FROM
      unnest(tags) g(v);
  
  
      RETURN inserted;
  
  END $$
  language plpgsql;
  </code></pre>
  <p>Now I would also like to return the array of tags that was passed to the function together with the inserted row. basically something like this (which doesn't work, just for demonstaration):</p>
  <pre><code>SELECT inserted.*, tags as tags FROM inserted join tags INTO inserted;
  </code></pre>
  <p>But I don't know how to combine 2 variables into a single one. Is there a way to do this?</p>