Repository navigation
Return Decimal values from Array(Numeric()) columns in SQLite - #1445
Merged
dantownsend merged 1 commit intoOct 28, 2026
Merged
Conversation
piccolo-orm#1342 registered an `ARRAY_NUMERIC` converter, but `Array.column_type` only used the `ARRAY_*` types for date / time columns, so `Array(Numeric())` was still created as `ARRAY` and the values came back as floats. Decimals are stored as JSON numbers, so the array converter also has to convert numbers, not just strings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks for this - what you've said does sound right. |
Member
|
I tested it locally with this little script and it all seems to work great - thanks! import asyncio
from decimal import Decimal
from piccolo.columns.column_types import Array, Numeric
from piccolo.engine.sqlite import SQLiteEngine
from piccolo.table import Table, create_db_tables
DB = SQLiteEngine()
class ArrayNumeric(Table, db=DB):
array = Array(Numeric())
async def main():
await create_db_tables(ArrayNumeric, if_not_exists=True)
row = ArrayNumeric(
{
ArrayNumeric.array: [
Decimal("1.0"),
Decimal("5.32"),
]
}
)
await row.save()
rows = await ArrayNumeric.select().first()
assert isinstance(rows["array"][0], Decimal)
if __name__ == "__main__":
asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1444 (follow-up to #1342, related to #941).
#1342 registered an
ARRAY_NUMERICconverter, butArray.column_typeonly uses theARRAY_*column types forDate/Time/Timestamp/Timestamptz, so the column was still created asARRAYand the converter never ran. Also, decimals are stored as JSON numbers, whileconvert_complex_array_outonly converted strings.This adds
Numericto theARRAY_*column types, and converts numbers inconvert_complex_array_out. Both are needed: with either one alone the values still come back as floats. The existing test passed because50.0 == Decimal("50.0"), so I added a type check.Existing SQLite tables keep their
ARRAYcolumn type, so they behave as before. Nested arrays,Noneelements and timestamp arrays work the same as before; on Postgres this only adds anisinstancecheck since asyncpg already returnsDecimal.I used Claude Code to write this change.