3

I have to write a function in PLPGSQL but I have problem with the function body quoted with dollar-quoting. Using the first tutorial:

CREATE FUNCTION inc(val integer) 
RETURNS integer AS 
$BODY$
BEGIN
    RETURN val + 1;
END; 
$BODY$
LANGUAGE PLPGSQL;

I get an error:

unterminated dollar-quoted string at or near $$

Searching on google I just found it's a JDBC Driver problem but I cannot update it. So I have tried to change the DELIMITER to remove $$:

DELIMITER ++;
CREATE FUNCTION inc(val integer) 
RETURNS integer AS 
++BODY++
BEGIN
    RETURN val + 1;
END; 
++BODY++
LANGUAGE PLPGSQL;
DELIMITER ;

The command doesn't return any error but function doesn't exists when I try to call it:

select inc(4);

enter image description here

What am I missing?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
EviSvil
  • 510
  • 3
  • 21

1 Answers1

2

The underlying problem is JDBC's inability to deal with dollar-quotes.
I think this was fixed with JDBC version 9.4.1208 (2016-02-16).

See:

You can avoid the problem by using plain quotes for the simple case:

CREATE FUNCTION inc(val integer) 
  RETURNS integer AS 
'
BEGIN
   RETURN val + 1;
END 
' LANGUAGE plpgsql;

See:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228