title: In plpgsql, return set of composite type without cast?
body: <p>This works, but I need the casts (<code>::name_value_pair</code>) That seems a bit ugly to me. Is there a way to do it without the casts?</p>
  
  <pre><code>create type name_value_pair as (name text, value text);
  
  create or replace function test1()
     returns setof name_value_pair
  as $$
  begin
      return next ROW('email', 'foo@example.com')::name_value_pair;
      return next ROW('user_id', 'abc123')::name_value_pair;
      return;
  end;
  $$ language plpgsql;
  </code></pre>
  
  <p>Here's the error without the cast. How does it not know it's a <code>text</code>? I thought a single quoted string literal was a <code>text</code> unless you cast it to something else.</p>
  
  <pre><code>psql: ERROR:  returned record type does not match expected record type
  DETAIL:  Returned type unknown does not match expected type text in column 1.
  CONTEXT:  PL/pgSQL function test1() line 4 at RETURN NEXT
  </code></pre>
  
  <p>The select: </p>
  
  <pre><code>=&gt; select * from test1();
    name   |      value      
  ---------+-----------------
   email   | foo@example.com
   user_id | abc123
  </code></pre>
  
  <p>I'm using PostgreSQL 12 beta.</p>