1
votes
declare r double precision; b double precision; c double precision;
begin

  r:=9.2;
  b:=2.3;
  c:=r/b;

  select log(2.7, c);
  ...

But I get an error for this code:

ERROR: function log(numeric, double precision) does not exist LINE 1: select log(2.7, c)

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

QUERY: select log(2.7, c) CONTEXT: PL/pgSQL function inline_code_block line 11 at SQL statement SQL state: 42883

2

2 Answers

3
votes

As documented in the manual the log() function with two arguments requires numeric not double precision

do
$$
declare
  r numeric; 
  b numeric; 
  c numeric;
  result numeric;
begin

  r:=9.2;
  b:=2.3;
  c:=r/b;

  result := log(2.7, c);
  raise notice 'Result %', result;
end;
$$
1
votes

The log function in PostgreSQL with two arguments requires NUMERIC parameters:

 \df log 
                          List of functions
   Schema   | Name | Result data type | Argument data types |  Type  
------------+------+------------------+---------------------+--------
 pg_catalog | log  | double precision | double precision    | normal
 pg_catalog | log  | numeric          | numeric             | normal
 pg_catalog | log  | numeric          | numeric, numeric    | normal

So you should cast your second argument or use a numeric variable instead:

SELECT LOG(2.7, c::NUMERIC);