Re: c language functions - Mailing list pgsql-hackers

From Rodrigo Barboza
Subject Re: c language functions
Date
Msg-id CANs8QJYbChbT66X=a5oNx3SfvKP5smzLxbdT-7KZKbRF_fdEBA@mail.gmail.com
Whole thread Raw
In response to Re: c language functions  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: c language functions
List pgsql-hackers
<div dir="ltr">Why not useful?<div style="style">If I don't make it receive anyelement, I will have to create an add
functionfor each type.</div><div style="style">Correct me if I'm wrong.</div></div><div class="gmail_extra"><br /><br
/><divclass="gmail_quote">On Wed, Apr 3, 2013 at 2:27 PM, Robert Haas <span dir="ltr"><<a
href="mailto:robertmhaas@gmail.com"target="_blank">robertmhaas@gmail.com</a>></span> wrote:<br /><blockquote
class="gmail_quote"style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div
class="h5">OnWed, Apr 3, 2013 at 11:26 AM, Rodrigo Barboza<br /> <<a
href="mailto:rodrigombufrj@gmail.com">rodrigombufrj@gmail.com</a>>wrote:<br /> > Hello.<br /> > I'm trying to
createa generic add function.<br /> > I have defined a type my_uint and it needs a '+' operator.<br /> > This
operatorshould work like normal int + int operation.<br /> > The function is defined expecting arguments (my_uint,
anyelement).<br/> ><br /> > I'm confused in retrieving the anyelement type, value and than do the add<br /> >
operationand return the correct value and type.<br /> > I tried to use PG_GETARG_DATUM, but I don't know how to
extractthe value<br /> > from it (should it be a uint32, uint64, float or double).<br /> ><br /> > Any
tips?<br/><br /></div></div>Well, the information the function ends up receiving is going to<br /> depend on how the
functionis declared at an SQL level.  So if you are<br /> defining the function to take an argument of anyelement
(whichseems<br /> unlikely to be a useful thing to do, but let's suppose you do it<br /> anyway) then look at the C
codefor some other function that takes an<br /> anyelement argument and look at how that function unpacks it.<br /><br
/>Similarly, if you declare the function to take int4 argument, then go<br /> look at the C code function that takes an
int4argument and see what<br /> it does to unpack it.<br /><br /> --<br /> Robert Haas<br /> EnterpriseDB: <a
href="http://www.enterprisedb.com"target="_blank">http://www.enterprisedb.com</a><br /> The Enterprise PostgreSQL
Company<br/></blockquote></div><br /></div> 

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Drastic performance loss in assert-enabled build in HEAD
Next
From: Tom Lane
Date:
Subject: Re: Regex with > 32k different chars causes a backend crash