Call Function in Pocket Query

How can I call a Postgresql function that returns a refcursor?

4 answers

Sorry for the late reply! I will set up PocketQuery in a Postgres environment and write an answer.

Hi Albert!

So I gave it a try and it works quite well. The only requirement is that you define your Postgres function in your database directly (i.e. in your database tool) and not in PocketQuery. For example, I added this function to my database via SquirrelSQL:

CREATE FUNCTION print_pocketquery (text) RETURNS TEXT AS '
    BEGIN
        RETURN $1 || $1;
    END;
' LANGUAGE 'plpgsql';

This is my PocketQuery query:

SELECT print_pocketquery(:text);

In the macro browser, I enter this for the variable "text": "PocketQuery-Rocks!!"

Output is: "PocketQuery-Rocks!! PocketQuery-Rocks!! "

Let me know if you need further help!

Regards, Felix [Scandio]

Hi Felix,

 

   I Appreciate your answer but your function returns text not a refcursor. Try to call this one:

 

CREATE OR REPLACE FUNCTION TEST_FUNCTION() RETURNS refcursor AS $$
DECLARE
      result refcursor := 'Result Text';
BEGIN
      RETURN result;
END;
$$ LANGUAGE plpgsql STRICT;


select TEST_FUNCTION();

 

 Thank you,

Albert

 

Hi Albert,

Did you set up your function in a PocketQuery query or in your database itself? Please see my comment above: "The only requirement is that you define your Postgres function in your database directly (i.e. in your database tool) and not in PocketQuery."

If you have both the function and the select statement in one PocketQuery query, it won't work at all, because one query in PocketQuery must be exactly one statement.

Regards, Felix [Scandio]

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Marketplace Apps

Tips on how to choose the best estimation method for your planning

Planning and grooming sessions all come with their own sets of rules. Team members meet to estimate stories or other work items, all according to an agreed-upon process. And with every session comes ...

65 views 0 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you