Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6003617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:49+00:00 2026-05-23T01:08:49+00:00

I have a program that reads financial data in JSON and inserts it into

  • 0

I have a program that reads financial data in JSON and inserts it into an SQLite database. The problem is when I’m inserting it into SQLite numeric column and it doesn’t seem to like the decimal object.

I’ve found this question answered before, but the answer is outdated and from what I understand SQLite now has a currency data type called numeric.

Right now as a workaround I’m storing decimal values as text, but is it possible to store it as numeric? Am I stuck with the overhead of converting decimals to strings and vice versa for database inserts and financial calculations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:08:50+00:00Added an answer on May 23, 2026 at 1:08 am

    sqlite3 allows you to register an adapter (to transparently convert Decimals to TEXT when inserting) and a converter (to transparently convert TEXT into Decimals when fetching).

    The following is a lightly modified version of the example code from the docs:

    import sqlite3
    import decimal
    D=decimal.Decimal
    
    def adapt_decimal(d):
        return str(d)
    
    def convert_decimal(s):
        return D(s)
    
    # Register the adapter
    sqlite3.register_adapter(D, adapt_decimal)
    
    # Register the converter
    sqlite3.register_converter("decimal", convert_decimal)
    
    d = D('4.12')
    
    con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)
    cur = con.cursor()
    cur.execute("create table test(d decimal)")
    
    cur.execute("insert into test(d) values (?)", (d,))
    cur.execute("select d from test")
    data=cur.fetchone()[0]
    print(data)
    print(type(data))
    
    cur.close()
    con.close()
    

    yields

    4.12
    <class 'decimal.Decimal'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that reads data from a file line-by-line. I would like
I have a program that reads arbitrary data from a file system and outputs
I have a PHP program that reads from the database and generated formatted sheets.
good day sirs. i have a small program that reads and processes data via
I have a python-based program that reads serial data off an a port connected
I currently have a simple database program that reads keys in from a text
Question is: Write a program that reads data into an array of type int.
actually i have a java program that reads the data from a specific XML
I have a program that reads a bunch of text and analyzes it. The
I have a program that reads and writes very large text files. However, because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.