Problem with sqlite3 and Decimal (fwd)

Igor Korot ikorot01 at gmail.com
Fri Dec 11 09:41:05 EST 2015


 Hi, Frank,

On Fri, Dec 11, 2015 at 9:27 AM, Frank Millman <frank at chagford.com> wrote:
> "Igor Korot"  wrote in message
> news:CA+FnnTyaLLEsYGU7v2BreySDOQ1rVsMzJ=5f4iQTLW3=tn=E+Q at mail.gmail.com...
>
>> Hi,
>>
>> > To: python-list at python.org
>> > From: "Frank Millman" <frank at chagford.com>
>> > Subject: Problem with sqlite3 and Decimal
>> > Date: Fri, 11 Dec 2015 11:21:53 +0200
>> > Lines: 71
>> >
>> > Hi all
>> >
>> > I need to store Decimal objects in a sqlite3 database, using Python 3.4
>> > > on
>> > Windows 7.
>> >
>
> [...]
>>
>>
>> >
>> > I noticed one oddity - I am asking sqlite3 to store the value as a >
>> > string,
>> > but then I am asking it to perform arithmetic on it.
>>
>> Is there a reason you are saving it as the string?
>> What happens when you save it as decimal?
>>
>
> Well, maybe you know something that I don't, but my understanding is that
> sqlite3 has a very limited range of supported data types, and decimal is not
> one of them.
>
> The stackoverflow article explains how to emulate a decimal type, and it
> works well most of the time.
>
> I found that I could reproduce the problem using sqlite3 directly, without
> using Python, so I have sent a post to the sqlite3 mailing list. I will
> report back with any info received.

Yes, I saw your post to sqlite3 ML.
And I do know that by default sqlite3 does not have many types supported.

However, all you need to do is save it as DECIMAL(10,2).
It is supported is sqlite3 and it will have NUMERIC affinity (ref 1)
or REAL (ref 2), which means the data will
be stored as decimals and not a string.

Ref.: 1) http://www.tutorialspoint.com/sqlite/sqlite_data_types.htm
2) https://www.sqlite.org/datatype3.html

Thank you.

>
> Frank
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list