Re: [PATCH] Fix conversion for Decimal arguments in plpython functions - Mailing list pgsql-hackers
From | Szymon Guz |
---|---|
Subject | Re: [PATCH] Fix conversion for Decimal arguments in plpython functions |
Date | |
Msg-id | CAFjNrYuPEeNLAPbjiFq0mydupXQScC+=MzOXVpEE+5s8JUYb+w@mail.gmail.com Whole thread Raw |
In response to | Re: [PATCH] Fix conversion for Decimal arguments in plpython functions (Claudio Freire <klaussfreire@gmail.com>) |
List | pgsql-hackers |
<div dir="ltr"><br /><div class="gmail_extra"><br /><br /><div class="gmail_quote">On 28 June 2013 22:29, Claudio Freire<span dir="ltr"><<a href="mailto:klaussfreire@gmail.com" target="_blank">klaussfreire@gmail.com</a>></span> wrote:<br/><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><divclass="h5">On Fri, Jun 28, 2013 at 5:14 PM, Steve Singer <<a href="mailto:steve@ssinger.info">steve@ssinger.info</a>>wrote:<br /> > On 06/27/2013 05:04 AM, Szymon Guz wrote:<br/> >><br /> >> On 27 June 2013 05:21, Steve Singer <<a href="mailto:steve@ssinger.info">steve@ssinger.info</a><br/> >> <mailto:<a href="mailto:steve@ssinger.info">steve@ssinger.info</a>>>wrote:<br /> >><br /> >> On 06/26/2013 04:47PM, Szymon Guz wrote:<br /> >><br /> >><br /> >><br /> >><br /> >><br /> >><br />>> Hi Steve,<br /> >> thanks for the changes.<br /> >><br /> >> You're idea about common code fordecimal and cdecimal is good, however<br /> >> not good enough. I like the idea of common code for decimal and cdecimal.<br/> >> But we need class name, not the value.<br /> >><br /> >> I've changed the code from str(x)to x.__class__.__name__ so the function<br /> >> prints class name (which is Decimal for both packages), notthe value. We<br /> >> need to have the class name check. The value is returned by the function and<br /> >>is a couple of lines lower in the file.<br /> >><br /> >> patch is attached.<br /> >><br /> ><br/> > I think the value is more important than the name, I want to the tests to<br /> > make sure that the conversionis actually converting properly. With your<br /> > method of getting the class name without the module we canhave both.<br /> ><br /> > The attached patch should print the value and the class name but not the<br /> > modulename.<br /><br /><br /></div></div>Why not forego checking of the type, and instead check the interface?<br /><br /><ahref="http://plpy.info" target="_blank">plpy.info</a>(x.as_tuple())<br /><br /> Should do.<br /><br /> >>> d = decimal.Decimal((0,(3,1,4),-2))<br /> >>> d.as_tuple()<br /> DecimalTuple(sign=0, digits=(3, 1, 4), exponent=-2)<br/> >>> d.as_tuple() == (0,(3,1,4),-2)<br /> True<br /> >>> d = decimal.Decimal("3.14")<br/> >>> d.as_tuple()<br /> DecimalTuple(sign=0, digits=(3, 1, 4), exponent=-2)<br /> >>>d.as_tuple() == (0,(3,1,4),-2)<br /> True<br /> >>><br /></blockquote></div><br /></div><div class="gmail_extra">Yea,however decimal and cdecimal have different outputs:</div><div class="gmail_extra"><br /></div><divclass="gmail_extra"><div class="gmail_extra">For decimal:</div><div class="gmail_extra"><br /></div><div class="gmail_extra">!INFO: DecimalTuple(sign=1, digits=(1, 0, 0), exponent=0)</div><div class="gmail_extra"><br /></div><divclass="gmail_extra">for cdecimal:</div><div class="gmail_extra"><br /></div><div class="gmail_extra">! INFO: DecimalTuple(sign=1, digits=(1, 0, 0), exponent=0L)</div></div></div>
pgsql-hackers by date: