0

I can compile the next function using psql client. However, DBeaver-ce returns the error

SQL Error [42601]: Unterminated dollar quote started at position 0 in SQL $$;. Expected terminating $$".

Why?

CREATE OR REPLACE FUNCTION numOf_icd10cm_4_snomed(oldCode TEXT)
RETURNS integer
LANGUAGE plpgsql
AS 
$$

-- This function returns the nunber of icd10cm codes matching oldCode in the table snomed2icd10

DECLARE
   quantity integer;  
BEGIN

   quantity := (select count(maptarget) 
             from 
                snomed2icd10
              where 
                 referencedcomponentid = oldCode
             );
    return quantity;

END;
$$;
Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56
  • 1
    Does this answer your question? [Unterminated dollar-quoted string at or near "$$](https://stackoverflow.com/questions/32634418/unterminated-dollar-quoted-string-at-or-near) –  Aug 17 '21 at 18:34

1 Answers1

1

Try enclosing the entire thing in a DbVis SQL block, using --/ and / to wrap the DDL (or DML), i.e.:

--/
CREATE OR REPLACE FUNCTION numOf_icd10cm_4_snomed(oldCode TEXT)
RETURNS integer
LANGUAGE plpgsql
AS 
$$

-- This function returns the nunber of icd10cm codes matching oldCode in the table snomed2icd10

DECLARE
   quantity integer;  
BEGIN

   quantity := (select count(maptarget) 
             from 
                snomed2icd10
              where 
                 referencedcomponentid = oldCode
             );
    return quantity;

END;
$$;
/
JJ Ward
  • 99
  • 7