Re: c language functions
От | Rodrigo Barboza |
---|---|
Тема | Re: c language functions |
Дата | |
Msg-id | CANs8QJYbChbT66X=a5oNx3SfvKP5smzLxbdT-7KZKbRF_fdEBA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: c language functions (Robert Haas <robertmhaas@gmail.com>) |
Ответы |
Re: c language functions
|
Список | 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 по дате отправления: