我想將多個查詢分組到一個生活在PostgreSQL中的函數中。該函數將使用PDO進行查詢。您可以使用PDO和PostgreSQL返回多個結果集嗎?
功能是:
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;
這裏的PHP代碼。 「數據庫」作爲設置常用連接屬性的單例類,沒有什麼特別的。
$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();
並且結果。
PDOException: SQLSTATE[IM001]: Driver does not support this function: driver does not support multiple rowsets in xxxx.php on line 32
這似乎表明它不被支持,但是再次,我找不到一個清楚地定義是什麼的列表。
有沒有人設法使此工作?
參考文獻:
- http://www.sitepoint.com/forums/showthread.php?p=3040612#post3040612
- PostgreSQL function returning multiple result sets
- http://ca.php.net/manual/en/pdostatement.nextrowset.php
這是一個相當複雜的調度過程,因此返回多個父表和子表。有幾個查詢共享參數,它會在數據庫上更快,另外我想將它分組以便於維護並減少往返。呃,好吧.. – 2009-06-06 13:53:29