Re: Argument casting hierarchy?

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Argument casting hierarchy?
Дата
Msg-id 62454612-6eed-de1e-45a6-23943b42d82d@aklaver.com
обсуждение исходный текст
Ответ на Argument casting hierarchy?  (Wells Oliver <wells.oliver@gmail.com>)
Ответы Re: Argument casting hierarchy?  (Wells Oliver <wells.oliver@gmail.com>)
Список pgsql-general
On 7/1/19 12:18 PM, Wells Oliver wrote:
> Hi guys, hoping you can help clarify what the 'hierarchy' of casts might 
> be in function arguments.
> 
> Meaning I have the following two functions
> 
> stats.foo1 (a bigint, b bigint) returns a/b::numeric
> 
> stats.foo1 (a real, b real) returns a/b::numeric
> 
> It's essentially the same function, but I thought I had to create two to 
> accept the different types.
> 
> However, when I call stats.foo1(3::smallint, 4::smallint) I receive the old:
> 
> ERROR:  function stats.foo(smallint, smallint) is not unique
> 
> Along w/ the message to explicitly cast.
> 
> I am essentially trying to write one function that will cast "down", I 
> guess, anything smaller than what's passed. I am guessing I only need 
> the real/real argument signature, but I wanted some clarity from the group.

 From the system catalogs, where float4 = real:

select typname AS cast_target  from pg_cast join pg_type on 
pg_cast.casttarget = pg_type.oid  where castsource = 'float4'::regtype;
  cast_target
-------------
  int8
  int2
  int4
  float8
  numeric

select typname AS cast_target  from pg_cast join pg_type on 
pg_cast.casttarget = pg_type.oid  where castsource = 'numeric'::regtype;
  cast_target
-------------
  int8
  int2
  int4
  float4
  float8
  money
  numeric
(7 rows)



> 
> I appreciate it.
> 
> -- 
> Wells Oliver
> wells.oliver@gmail.com <mailto:wellsoliver@gmail.com>


-- 
Adrian Klaver
adrian.klaver@aklaver.com



В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Statistics tables not being updated anymore
Следующее
От: Wells Oliver
Дата:
Сообщение: Re: Argument casting hierarchy?