Re: problem with money datatype based calculations in python

2009-05-03 Thread Krishnakant
On Sun, 2009-05-03 at 03:20 +, D'Arcy J.M. Cain wrote:
 Sorry, I should have mentioned my bias.  :-)
 No problems at all.  It is a very good library.  I get an impression that it 
 is realy a mature module and a very powerful set of API. 

  I would like to know if it has been tested with postgresql 8.3 and are
 
 The current version of PyGreSQL has been tested with Python 2.5 and
 PostGreSQL 8.3. Older version should work as well, but you will need
 at least Python 2.3 and PostgreSQL 7.4.
 
Ah, I am using python 2.6 and postgresql 8.3

I am really impressed with the library.  I want some manual or tutorial
for the same and if possible can you write me off the list with a small
tutorial for things like connecting to the database, sending queries,
and working with the resultset at the client site.

I will be really happy if this library also supports calling a stored
procedurs directly.  Psycopg2 does not have such a feature and I had to
create one small module which does that work.

What it does is that you just give the name of the procuedure procedure
as the first parameter and a list of arguements as the second parameter.
That's all, you will get the result because the query  for the call is
created inside the module and the programmer need not worry about what
the sored procedure looks like.

Never the less I am expecting that pygresql has some infrastructure for
making calls to the stored procedures.  Please send me some tutorial off
the list.

happy hacking.
Krishnakant.


--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread Günther Dietrich
Krishnakant krm...@gmail.com wrote:

['money datatype' for database stored values]

What ist the real problem? Do you have problems converting results of 
float calculations to the 'money datatype' before storing them in the 
database, or do you want to avoid the precision issues which come with 
the conversion od non-integer values between binary and decimal?
In the latter case use the Decimal data type from module decimal (comes 
with the python distribution -- it is mentioned in the tutorial).



Regards,

Günther
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread anusha k
Do calculations in postgresql and then call that calculated value from the
python.So no need to calculate in python at all


Njoy the share of Freedom,
Anusha Kadambala
On Sat, May 2, 2009 at 1:15 PM, Krishnakant krm...@gmail.com wrote:

 hello all,
 I am using postgresql as a database server for my db application.

 The database is related to accounts and point of sales and many
 calculations involve money datatype.

 The application logic is totally done in python.  Now the problem is
 that there is a situation where we calculate tax on % of the total
 amount on the invoice.  The  percentage is in terms of float but the
 eventual amount has to be in a money datatype.

 The product cost comes in money datatype from postgresql and the tax %
 comes in float.  So I would like to know if python supports some thing
 similar to money datatype so that I can cast my total amount (in money )
 divided by tax% (in float ) so money divided by float should be the
 result and that result should be in money datatype.
 For example a product x has the cost Rs. 100 which is stored in the
 tabel as money type.  and in the tax table for that product the VAT is
 5% and this 5% is stored in float datatype.  So after using both these
 values the resulting total 105Rs. should be in money type and not float.
 I awaite some reply,
 Thanks in advice.
 happy hacking.
 Krishnakant.

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread Dave Angel

Krishnakant wrote:

hello all,
I am using postgresql as a database server for my db application.

The database is related to accounts and point of sales and many
calculations involve money datatype.

The application logic is totally done in python.  Now the problem is
that there is a situation where we calculate tax on % of the total
amount on the invoice.  The  percentage is in terms of float but the
eventual amount has to be in a money datatype.

The product cost comes in money datatype from postgresql and the tax %
comes in float.  So I would like to know if python supports some thing
similar to money datatype so that I can cast my total amount (in money )
divided by tax% (in float ) so money divided by float should be the
result and that result should be in money datatype.
For example a product x has the cost Rs. 100 which is stored in the
tabel as money type.  and in the tax table for that product the VAT is
5% and this 5% is stored in float datatype.  So after using both these
values the resulting total 105Rs. should be in money type and not float.
I awaite some reply,
Thanks in advice.
happy hacking.
Krishnakant.


  
Tax rate isn't divided, it's multiplied.  But probably that's just a 
typo in your message.


Short answer is use your money class to convert the float into money.  
And then test, to see that's really what you wanted.  Be sure and check 
the edge cases, because float is a binary system, and you can get both 
quantization and rounding problems converting between them.


Is the money you're dealing with decimal-based?  So maybe money values 
are integers plus two more digits of fractional precision?


It's going to be tough for somebody with no access to that money type 
to guess what your problem is.  What operations does it currently 
support?  If it supports multiply, then just change the tax rate to be a 
money type.  Unless of course you might have a tax rate of 5.221%   Does 
your money class support accurate conversion to class decimal?  In that 
case, convert to decimal, multiply, then convert back.


Or if money is really a fixed-point class, with assumed two digits, 
multiply the cost by 100 and convert to int.  Multiply by the tax, and 
convert back.


You also need to specify the government rules for the multiply.  Is 
rounding permitted, or must all fractions of a penny (assumption there) 
be rounded up?


Or switch everything to class decimal in the standard python library,  
You still have most of the questions to answer, but at least you'd be 
asking on the right forum.



--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread D'Arcy J.M. Cain
On Sat, 02 May 2009 15:43:23 +0200
Günther Dietrich guenther.dietr...@spamfence.net wrote:
 Krishnakant krm...@gmail.com wrote:
 
 ['money datatype' for database stored values]
 
 What ist the real problem? Do you have problems converting results of 
 float calculations to the 'money datatype' before storing them in the 
 database, or do you want to avoid the precision issues which come with 
 the conversion od non-integer values between binary and decimal?
 In the latter case use the Decimal data type from module decimal (comes 
 with the python distribution -- it is mentioned in the tutorial).

And if you use PyGreSQL (http://www.PyGreSQL.org/) to connect to
the database then the money type is already converted to Decimal.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread Peter Pearson
On Sat, 02 May 2009 13:15:22 +0530, Krishnakant krm...@gmail.com wrote:
 hello all,
 I am using postgresql as a database server for my db application.

 The database is related to accounts and point of sales and many
 calculations involve money datatype.
[snip]

As far as I can tell, Python has no type money.  Is money
a class defined by some postgresql module you're using?  A
very small amount of specific information (e.g., a five-line
sample program that demonstrates the problem) would greatly
improve your chances of getting useful help.

-- 
To email me, substitute nowhere-spamcop, invalid-net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread Krishnakant
On Sat, 2009-05-02 at 11:57 -0400, D'Arcy J.M. Cain wrote:
 And if you use PyGreSQL (http://www.PyGreSQL.org/) to connect to
 the database then the money type is already converted to Decimal.
 d'arcy, I visited the home page for pygresql and discovered that you wrote 
 the library.
I am happy that you also included a non-dbapi (postgresql classic
interface ) along with the standard DBAPI module.

I would like to know if it has been tested with postgresql 8.3 and are
there any known bottlenecks while using this driver module on large
scale database opperations?
Is this actively maintained?
Perhaps this might be off topic but may I ask, how is pypgsql, 
  
Has any one used pgsql for any postgresql based software?
and between pygresql and pypgsql which one is more maintained?

the system I am developing is a mission critical financial application
and I must be pritty sure about any module I am using.

happy hacking.
Krishnakant.



--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread John Machin
On May 3, 12:09 am, Dave Angel da...@ieee.org wrote:
 Krishnakant wrote:
  hello all,
  I am using postgresql as a database server for my db application.

  The database is related to accounts and point of sales and many
  calculations involve money datatype.

  The application logic is totally done in python.  Now the problem is
  that there is a situation where we calculate tax on % of the total
  amount on the invoice.  The  percentage is in terms of float but the
  eventual amount has to be in a money datatype.

  The product cost comes in money datatype from postgresql and the tax %
  comes in float.  So I would like to know if python supports some thing
  similar to money datatype so that I can cast my total amount (in money )
  divided by tax% (in float ) so money divided by float should be the
  result and that result should be in money datatype.
  For example a product x has the cost Rs. 100 which is stored in the
  tabel as money type.  and in the tax table for that product the VAT is
  5% and this 5% is stored in float datatype.  So after using both these
  values the resulting total 105Rs. should be in money type and not float.
  I awaite some reply,
  Thanks in advice.
  happy hacking.
  Krishnakant.

 Tax rate isn't divided, it's multiplied.  But probably that's just a
 typo in your message.

 Short answer is use your money class to convert the float into money.  
 And then test, to see that's really what you wanted.  Be sure and check
 the edge cases, because float is a binary system, and you can get both
 quantization and rounding problems converting between them.

 Is the money you're dealing with decimal-based?  So maybe money values
 are integers plus two more digits of fractional precision?

 It's going to be tough for somebody with no access to that money type
 to guess what your problem is.  What operations does it currently
 support?  If it supports multiply, then just change the tax rate to be a
 money type.

Aarrgghh!! If the money type supports multiplying money by money,
the author should be put in the stocks and pelted with rotten
vegetables.

(IMHO)

--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread D'Arcy J.M. Cain
On Sun, 03 May 2009 00:07:17 +0530
Krishnakant krm...@gmail.com wrote:
 On Sat, 2009-05-02 at 11:57 -0400, D'Arcy J.M. Cain wrote:
  And if you use PyGreSQL (http://www.PyGreSQL.org/) to connect to
  the database then the money type is already converted to Decimal.
  d'arcy, I visited the home page for pygresql and discovered that you wrote 
  the library.

Sorry, I should have mentioned my bias.  :-)

 I am happy that you also included a non-dbapi (postgresql classic
 interface ) along with the standard DBAPI module.

That interface existed before there was a DB-API spec.  We added the
DB-API interface later and decided to support both.

 I would like to know if it has been tested with postgresql 8.3 and are

The current version of PyGreSQL has been tested with Python 2.5 and
PostGreSQL 8.3. Older version should work as well, but you will need
at least Python 2.3 and PostgreSQL 7.4.

 there any known bottlenecks while using this driver module on large
 scale database opperations?

None that I know of.  It is used on some pretty big databases that I
know of.

 Is this actively maintained?

Yes.

I'll leave the rest of the questions for someone less biased.  :-)

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list