postgres查询没有结果数据的目的地

时间:2014-06-24 17:22:39

标签: postgresql

我对pgSQL很新。

任何人都可以帮助解决此错误吗?

ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function prac_data.document_get_document_title(integer) line 8 at SQL statement

脚本是......

CREATE OR REPLACE FUNCTION prac_data.document_get_document_title(documentid INTEGER) RETURNS TEXT
AS
$body$
DECLARE
xmlText XML;
rawText TEXT;
BEGIN
    SELECT document into STRICT rawText FROM prac_data.document_table WHERE entity_id = documentid;
    xmlText := XMLParse (DOCUMENT rawText);            
    SELECT xpath('/inps_flow_document/@title', xmlText) as titleText;
    RETURN titleText;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
            RAISE EXCEPTION 'document_id % not found', documentid;
END;
$body$ LANGUAGE PLPGSQL;


SELECT prac_data.document_get_document_title(1)

我正在使用SELECT(可以看到),但也许我没有正确使用它......

1 个答案:

答案 0 :(得分:2)

尝试类似:

CREATE OR REPLACE FUNCTION prac_data.document_get_document_title(documentid INTEGER) RETURNS TEXT
AS
$body$
DECLARE
xmlText XML;
rawText TEXT;
titleText TEXT;
BEGIN
    SELECT document into STRICT rawText FROM prac_data.document_table WHERE entity_id = documentid;
    xmlText := XMLParse (DOCUMENT rawText);            
    titleText := xpath('/inps_flow_document/@title', xmlText);
    RETURN titleText;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
            RAISE EXCEPTION 'document_id % not found', documentid;
END;
$body$ LANGUAGE PLPGSQL;