PostgreSQL: function returns multiple recordsets: how to read in c#? -


using link http://www.sqlines.com/postgresql/npgsql_cs_result_sets have created example, not work: there function:

 create or replace function show_cities_multiple()   returns setof refcursor $$     declare       ref1 refcursor;        ref2 refcursor;                                  begin       open ref1 select user_id, user_name users;       return next ref1;         open ref2 select id, company customers;       return next ref2;           end;     $$ language plpgsql; 

the 1st loop reads recordsets names , can read function.

         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 output - names of cursors recordsets // <unnamed portal 1> // <unnamed portal 2>                  dr.nextresult();  // there nothing read, no additional recordsets                 while (dr.read())                     console.write("{0}\t{1} \n", dr[0], dr[1]);                  tran.commit();                 conn.close(); 

what wrong? how read multiple recordsets pgsql function?

there few ways work cursors different versions

how can cursor data calling stored procedure in npgsql


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -