Call Function in Pocket Query

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

4 answers

This widget could not be displayed.

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

This widget could not be displayed.

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]

This widget could not be displayed.

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

 

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published 52m ago in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

15 views 0 3
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