From: | Rodrigo Barboza <rodrigombufrj(at)gmail(dot)com> |
---|---|
To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: c language functions |
Date: | 2013-04-03 17:53:33 |
Message-ID: | CANs8QJYbChbT66X=a5oNx3SfvKP5smzLxbdT-7KZKbRF_fdEBA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Why not useful?
If I don't make it receive anyelement, I will have to create an add
function for each type.
Correct me if I'm wrong.
On Wed, Apr 3, 2013 at 2:27 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Wed, Apr 3, 2013 at 11:26 AM, Rodrigo Barboza
> <rodrigombufrj(at)gmail(dot)com> wrote:
> > Hello.
> > I'm trying to create a generic add function.
> > I have defined a type my_uint and it needs a '+' operator.
> > This operator should work like normal int + int operation.
> > The function is defined expecting arguments (my_uint, anyelement).
> >
> > I'm confused in retrieving the anyelement type, value and than do the add
> > operation and return the correct value and type.
> > I tried to use PG_GETARG_DATUM, but I don't know how to extract the value
> > from it (should it be a uint32, uint64, float or double).
> >
> > Any tips?
>
> Well, the information the function ends up receiving is going to
> depend on how the function is declared at an SQL level. So if you are
> defining the function to take an argument of anyelement (which seems
> unlikely to be a useful thing to do, but let's suppose you do it
> anyway) then look at the C code for some other function that takes an
> anyelement argument and look at how that function unpacks it.
>
> Similarly, if you declare the function to take int4 argument, then go
> look at the C code function that takes an int4 argument and see what
> it does to unpack it.
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2013-04-03 17:58:30 | Re: Regex with > 32k different chars causes a backend crash |
Previous Message | Tom Lane | 2013-04-03 17:36:53 | Re: Drastic performance loss in assert-enabled build in HEAD |