title: PostgreSQL: function returns multiple recordsets: how to read in c#?
body: <p>Using this link
  <a href="http://www.sqlines.com/postgresql/npgsql_cs_result_sets" rel="nofollow noreferrer">http://www.sqlines.com/postgresql/npgsql_cs_result_sets</a>
  I have created the example, but it does not work:
  There is my function:</p>
  
  <pre><code> CREATE OR REPLACE FUNCTION show_cities_multiple() 
   RETURNS SETOF refcursor AS $$
      DECLARE
        ref1 refcursor; 
        ref2 refcursor;                             
      BEGIN
        OPEN ref1 FOR SELECT user_id, user_name FROM users;
        RETURN NEXT ref1; 
  
        OPEN ref2 FOR SELECT id, company FROM customers;
        RETURN NEXT ref2;      
      END;
      $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>The 1st loop reads recordsets names only and that is all what I can read from the function.</p>
  
  <pre><code>         NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString());
                  conn.Open();
                  NpgsqlTransaction tran = conn.BeginTransaction();
                  NpgsqlCommand command = new NpgsqlCommand("show_cities_multiple", conn);
                  command.CommandType = CommandType.StoredProcedure;
                  NpgsqlDataReader dr = command.ExecuteReader();
                  while (dr.Read())
                  {
                     Console.Write("{0}\n", dr[0]);
                  }
  // ----------there is output - only names of cursors recordsets
  // &lt;unnamed portal 1&gt;
  // &lt;unnamed portal 2&gt;
  
                  dr.NextResult(); 
  // But there is nothing to read, no additional recordsets
                  while (dr.Read())
                      Console.Write("{0}\t{1} \n", dr[0], dr[1]);
  
                  tran.Commit();
                  conn.Close();
  </code></pre>
  
  <p>What is wrong? How to read multiple recordsets from a PGSQL function?</p>