From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Wells Oliver <wells.oliver@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Argument casting hierarchy?
Date: Mon, 1 Jul 2019 13:22:59 -0700
Message-ID: <541ea689-9aa2-30c5-f504-441bb85bbe26@aklaver.com> (raw)
In-Reply-To: <CAOC+FBUBf72TW0ERyr4rbexM9n990NNuJUSr0MENFz_dOapsiQ@mail.gmail.com>
References: <CAOC+FBVZzMgF5u91E8sFUPht_8s+Xy5PVxWQ1qncgZLCkM4sMQ@mail.gmail.com>
<62454612-6eed-de1e-45a6-23943b42d82d@aklaver.com>
<CAOC+FBUBf72TW0ERyr4rbexM9n990NNuJUSr0MENFz_dOapsiQ@mail.gmail.com>
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.klaver@aklaver.com
> <mailto:adrian.klaver@aklaver.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.oliver@gmail.com <mailto:wells.oliver@gmail.com>
> <mailto:wellsoliver@gmail.com <mailto:wellsoliver@gmail.com>>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
>
>
>
> --
> Wells Oliver
> wells.oliver@gmail.com <mailto:wellsoliver@gmail.com>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, wells.oliver@gmail.com
Subject: Re: Argument casting hierarchy?
In-Reply-To: <541ea689-9aa2-30c5-f504-441bb85bbe26@aklaver.com>
References: <CAOC+FBVZzMgF5u91E8sFUPht_8s+Xy5PVxWQ1qncgZLCkM4sMQ@mail.gmail.com> <62454612-6eed-de1e-45a6-23943b42d82d@aklaver.com> <CAOC+FBUBf72TW0ERyr4rbexM9n990NNuJUSr0MENFz_dOapsiQ@mail.gmail.com> <541ea689-9aa2-30c5-f504-441bb85bbe26@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox