Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6157797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:50:52+00:00 2026-05-23T20:50:52+00:00

I am using Postgresql 8.3 and have the following simple function that will return

  • 0

I am using Postgresql 8.3 and have the following simple function that will return a refcursor to the client

CREATE OR REPLACE FUNCTION function_1() RETURNS refcursor AS $$
DECLARE
        ref_cursor REFCURSOR;
BEGIN
        OPEN ref_cursor FOR SELECT * FROM some_table;
        RETURN (ref_cursor);    
END;
$$ LANGUAGE plpgsql;

Now , I can use the following SQL commands to call this function and manipulate the returned cursor ,but the cursor name is automatically generated by the PostgreSQL

BEGIN;
SELECT function_1();  --It will output the generated cursor name , for example , "<unnamed portal 11>" ;
FETCH 4   from  "<unnamed portal 11>"; 
COMMIT;

Besides explicitly declaring the cursor name as the input parameter of the function as described by 38.7.3.5. Returning Cursors, can I declare my own cursor name and use this cursor name to manipulate the returned cursor instead of Postgresql automatically generates for me ?

If not, are there any commands that can get the generated cursor name ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:50:53+00:00Added an answer on May 23, 2026 at 8:50 pm

    Yes, use:

    CREATE OR REPLACE FUNCTION function_1(refcursor) RETURNS refcursor AS $$
    BEGIN
            OPEN $1 FOR SELECT * FROM some_table;
            RETURN $1;    
    END;
    $$ LANGUAGE plpgsql;
    

    Result:

    SELECT function_1('myowncursorname');
       function_1
    -----------------
     myowncursorname
    (1 row)
    

    It looks like auto-generated name is <unnamed portal n>, where n is natural number (from 1).

    EDIT:

    As another way you could use pg_cursors view with such query to obtain generated cursor name:

    SELECT name FROM pg_cursors WHERE statement LIKE 'SELECT * FROM some_table';
    

    For example:

    BEGIN;
    SELECT function_1();
    SELECT name FROM pg_cursors WHERE statement LIKE 'SELECT * FROM some_table';
    COMMIT;
    

    Result:

         function_1
    --------------------
     <unnamed portal 3>
    (1 row)
    
            name
    --------------------
     <unnamed portal 3>
    (1 row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two PostgreSQL databases that have been created using the same sql file.
I am using Spring 3.0 with Hibernate and PostgreSQL and I have following problem:
Recently, I have been getting familiar with PostgreSQL(using 8.2) and found the date_trunc function
I have just installed PostgreSQL 8.3.4 on Mac OS X 10.5 (using ports), but
I've been using PostgreSQL a little bit lately, and one of the things that
I'm using Windows XP and I've installed PostgreSQL 8.3.5-2. I can create databases via
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I am using PostgreSQL. I have the data in table like: Parent_id Count Read
I am using PostgreSQL database. I have the data like below. id name1 name2
I'm using Hibernate and PostgreSQL 8.4 database in a Java application. I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.