problem with money datatype based calculations in python

K

Krishnakant

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.
 
G

Günther Dietrich

['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
 
D

D'Arcy J.M. Cain

['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.
 
P

Peter Pearson

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.
 
K

Krishnakant

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.
 
D

D'Arcy J.M. Cain

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. :)
 
K

Krishnakant

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top