I would like to group multiple queries into a single function that lives in PostgreSQL. The function will be queried using PDO.
The function is:
CREATE OR REPLACE FUNCTION "test_multipe_refcursor"()
RETURNS SETOF refcursor AS $BODY$
DECLARE
parentRC refcursor;
childRC refcursor;
BEGIN
open parentRC FOR
SELECT * FROM parent;
RETURN NEXT parentRC;
open childRC FOR
SELECT * FROM child;
RETURN NEXT childRC;
RETURN;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION "test_multipe_refcursor"() OWNER TO postgres;
Here's the PHP code. "Database" as a singleton class that sets up the usual connection properties, nothing special.
$database = Database::load();
$sql = "select * from test_multipe_refcursor();";
$p = $database->query($sql);
$i = 1;
do
{
$this->set('set' . $i, $p->fetchAll(PDO::FETCH_ASSOC));
$i++;
} while ($p->nextRowset());
$p->closeCursor();
And the result.
PDOException: SQLSTATE[IM001]: Driver does not support this function: driver does not support multiple rowsets in xxxx.php on line 32
This would seem to indicate that it's not supported, but then again, I cannot find a list defining exactly what is.
Has anyone managed to get this working?
References: