how can I get cursor data with calling stored procedure in npgsql

后端 未结 3 551
清酒与你
清酒与你 2020-12-03 23:33

I have looked into materials in www.npgsql.org, but couldn\'t find how to solve my problem...

Table, PostgreSQL

[City], [State]
\"Au         


        
3条回答
  •  感动是毒
    2020-12-03 23:59

    Npgsql 2.x had a feature whereby it automatically "dereferenced" cursors returned from functions. This feature was dropped from Npgsql 3.0; this is mentioned in our migration nodes for 3.0, and the discussion is in this issue. Since the cursor is simply returned and isn't dereferenced, Npgsql returns the cursor name itself (unnamed portal 1); you can now fetch results from this query by sending FETCH etc.

    However, as was mentioned, wrapping a single SELECT in a function doesn't make much sense. If you do need to write a function that returns a single resultset, make it return a SETOF or a TABLE instead of a cursor: CREATE FUNCTION ... RETURNS TABLE (column_name column_type [, ...]). Apart from being simpler and cleaner, this is also more efficient, as the query results are returned directly (dereferencing the cursor involves another database roundtrip).

    See the PostgreSQL docs for more info on how to define a function returning a table.

提交回复
热议问题