R
R
romaro2022-04-09 17:21:46
PostgreSQL
romaro, 2022-04-09 17:21:46

Why doesn't this function compile?

I'm using the community version of DBeaver and there might be a bug with it.

I'm trying to create a function:

CREATE OR REPLACE FUNCTION dao_subject.get_salt_by_contacts_s(p_props json)
RETURNS varchar
LANGUAGE plpgsql
AS $function$
DECLARE
  l_result		varchar;
  l_email 		TEXT	:= p_props ->> 'email';
  l_mobile_phone	TEXT	:= p_props ->> 'mobilePhone';
BEGIN
  SELECT s.password_salt INTO l_result FROM dao_subject.subject s
  WHERE s.email = l_email
    OR s.mobile_phone = l_mobile_phone;
  
  RETURN l_result;
END;
$function$
;


And I get an error:
SQL Error [42601]: Unterminated dollar quote started at position 0 in SQL $function$
;. Expected terminating $$


I replace the escaping of $function$ with $$ and the function is successfully created, although these constructs are syntactically equal.

Then I open a new console, stupidly copy the code of the function I just created, try to execute it and again the same error. With other functions, order.

So far, the only guess is that DBeaver in some cases incorrectly encodes some characters and postgres does not see them

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2022-04-09
@melkij

The request is correct. Look in the database logs to see what request your client actually sends.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question