0

I'm very new to pgSQL.

Can any one help with resolving this error?

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

The script is...

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)

im using SELECT into (as can been seen), but perhaps I'm not using it quite correctly....

1
  • try changing this SELECT xpath('/inps_flow_document/@title', xmlText) as titleText; to SELECT xpath('/inps_flow_document/@title', xmlText) into yourVariable as titleText; Commented Jun 24, 2014 at 17:24

1 Answer 1

2

Try something like:

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.