Call Function in Pocket Query

Albert Tomimatsu January 29, 2015

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

4 answers

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2015

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]

0 votes
Albert Tomimatsu February 27, 2015

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

 

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2015

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]

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2015

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events