Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create a table with float columns in strict mode #644

Open
agateau-gg opened this issue Nov 15, 2024 · 0 comments
Open

Can't create a table with float columns in strict mode #644

agateau-gg opened this issue Nov 15, 2024 · 0 comments

Comments

@agateau-gg
Copy link

Trying to create a table with float columns fails when strict mode is enabled.

Running this snippet:

from sqlite_utils import Database

db = Database("test.db")
db["test"].create({"frequency": float}, strict=True)

Causes this error:

Traceback (most recent call last):
  File "/home/agateau/tmp/sqliteutilsfloat.py", line 4, in <module>
    db["test"].create({"frequency": float}, strict=True)
  File "/home/agateau/.local/share/virtualenvs/40d64b18be55921/lib/python3.10/site-packages/sqlite_utils/db.py", line 1689, in create
    self.db.create_table(
  File "/home/agateau/.local/share/virtualenvs/40d64b18be55921/lib/python3.10/site-packages/sqlite_utils/db.py", line 1070, in create_table
    self.execute(sql)
  File "/home/agateau/.local/share/virtualenvs/40d64b18be55921/lib/python3.10/site-packages/sqlite_utils/db.py", line 526, in execute
    return self.conn.execute(sql)
sqlite3.OperationalError: unknown datatype for test.frequency: "FLOAT"

According to sqlite doc, the type for floats should be REAL. To verify this I modified db.py so that COLUMN_TYPE_MAPPING would return "REAL" for float. With this modification the example snippet runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant