Search code examples
mysqlfirebirdfirebird-3.0

How translate function from MySQL to Firebird?


how how can i transfer this function to firebird

create function `candidat`(in_num   decimal(10,2),
                           in_group integer unsigned)   
       returns integer unsigned 
       deterministic   
       language sql 
begin   
   return case in_group when 1 then floor(in_num / 3.0 + 0.99)
                        when 2 then floor(in_num / 3.0 + 0.50)
                               else floor(in_num / 3.0) end; 
end

Solution

  • You can create Firebird 3 PSQL function, which will be almost identical to the MySQL function. The mayor differences are just the creation syntax:

    create function candidat(in_num   decimal(10,2),
                             in_group integer)   
           returns integer
    as
    begin   
       return case in_group when 1 then floor(in_num / 3.0 + 0.99)
                            when 2 then floor(in_num / 3.0 + 0.50)
                                   else floor(in_num / 3.0) end; 
    end
    

    As Firebird doesn't have unsigned integers, you need to use a normal (signed) integer instead. Given the input that should be sufficient, otherwise consider switching to bigint.