0
CREATE OR REPLACE FUNCTION f_sync_from_xml()
  RETURNS boolean AS
$BODY$
DECLARE
    myxml    xml;
    datafile text := 'path/to/my_file.xml';
BEGIN

myxml := pg_read_file(datafile, 0, 100000000); 

This function returns error

ERROR: unterminated dollar-quoted string at or near "$BODY$

. How do I solve it?

3
  • is it the whole code?.. please post error as well Commented Nov 21, 2017 at 9:53
  • It is the whole code... error is string delimited from dollars not terminated Commented Nov 21, 2017 at 9:57
  • You are missing an end for the function body. Commented Nov 21, 2017 at 11:03

1 Answer 1

2

the definition is not completed, yo uneed to terminate it, eg:

CREATE OR REPLACE FUNCTION f_sync_from_xml()
  RETURNS boolean AS
$BODY$
DECLARE
    myxml    xml;
    datafile text := 'path/to/my_file.xml';
BEGIN

myxml := pg_read_file(datafile, 0, 100000000); 

END;
$BODY$ language plpgsql;

here $BODY$ is a safe quote - function definition remains inside quotes

Sign up to request clarification or add additional context in comments.

2 Comments

CREATE TEMP TABLE tmp AS SELECT (xpath('//some_id/text()', x))[1]::text AS id FROM unnest(xpath('/xml/path/to/datum', myxml)) x;
please don't debug in comments - if you meet problem you can't solve after reading docs and googling - post a new question

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.