Search code examples
postgresqlplpgsqldbeaverdollar-quoting

DBeaver not compiling a function that compiles using psql client


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;
$$;

Solution

  • 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;
    $$;
    /