Re: Argument casting hierarchy?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Argument casting hierarchy?
Date: 2019-07-01 20:22:59
Message-ID: 541ea689-9aa2-30c5-f504-441bb85bbe26@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 7/1/19 1:18 PM, Wells Oliver wrote:
> What is it you're showing me exactly? The valid numeric types accepted
> (and cast) by both real and numerics?

That there is builtin casting for a source of either float4 or numeric
to the types listed respectively and that numeric offers more choices.
Might help you decide on which type you want to use for a single function.

>
> On Mon, Jul 1, 2019 at 1:15 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
>
> 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(dot)oliver(at)gmail(dot)com <mailto:wells(dot)oliver(at)gmail(dot)com>
> <mailto:wellsoliver(at)gmail(dot)com <mailto:wellsoliver(at)gmail(dot)com>>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
>
>
>
> --
> Wells Oliver
> wells(dot)oliver(at)gmail(dot)com <mailto:wellsoliver(at)gmail(dot)com>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2019-07-01 20:38:54 Re: Statistics tables not being updated anymore
Previous Message Wells Oliver 2019-07-01 20:18:28 Re: Argument casting hierarchy?