You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to store a list or similar types directly to the database.
Currently this does not seem to be the case. The above example code gives me the following error:
InterfaceError: (sqlite3.InterfaceError) Error binding parameter 1 - probably unsupported type.
[SQL: INSERT INTO block (id, "values") VALUES (?, ?)]
[parameters: (0, ['test', 'test2'])]
(Background on this error at: https://sqlalche.me/e/14/rvf5)
Wanted Solution
I would like to directly use the List type (or similar types like Dicts) to store data to a database column. I would expect SQLModel to serialize them.
with partial success as a workaround for a small project.
Reacted by Jing Wang, Frédéric Branchaud-Charron, 庭羲, Quinn Blenkinsop, Toni Alatalo, Tianle Chen, Antonio Perez, Jonathan Vargas, Stefan Uddenberg, codezilla451 and 24 more
With Postgres, you can use an array of e.g. strings or ints. I'm having it as a Set on Python side to verify that don't get duplicates, but List works too. I think they are not supported in Sqlite though.
Reacted by Gustavo Soares, Emir Karamehmetoglu, Magnus Markling, eugene, Andrii Bovsunovskyi, Marek Dobransky, Joris Guerry, Matthieu LAURENT, BLTHDJ, Samo Kolter and 8 more
Reacted by Gustavo Soares, Matthew Aylward and Jonathan Vargas
Reacted by Gustavo Soares, voxofox and Pedro Xavier
Reacted by Abdulaziz Al-Homaid, gsouveton, Pedro Xavier, Rômulo Gadelha, Martin Thorsen Ranang and AzlanCoding
Reacted by Gustavo Soares, Jeremy T. Hetzel, Harpo, Brian Antonelli and michelclemer
With Postgres, you can use an array of e.g. strings or ints. I'm having it as a Set on Python side to verify that don't get duplicates, but List works too. I think they are not supported in Sqlite though.
Why this is not supported by default?
I mean, is it possible for the user to accomplish the sames as OP wants but without using values: List[str], maybe representing it on another way that SQLModel allows
I ended up doing what @mkarbo suggested
@FilipeMarch - I guess one issue is that SQLite does not have arrays, whereas Postgres does. I'm using List but it means I can't use SQLite. Which is fine in our case, we need pg support only.
Reacted by Filipe Marchesini and Emir Karamehmetoglu
This is probably not that high on the priority list as there are workarounds, but even just having a list column use a Column(JSON) under the hood and not needing arbitrary_types_allowed in the Pydantic config would be a massive upgrade.
Although of course, it would be best to use Column(ARRAY(...)) when possible, but that's probably a bit harder
@tiangolo this would be alot cleaner to have it recognized out of the box! :)
Reacted by Matthieu LAURENT, TarmoYli, Armand Rego, Ilja Baroŭski, cdrcqnts, gavin, Vinicius Aguiar, Martin Thorsen Ranang, Nikola Milovic, Thomas Schauer-Köckeis and 8 more
Reacted by Natalia Chodelski, Vinicius Aguiar, Data Engineering Funderz Group, Thomas Schauer-Köckeis, Fibert Loyee and Robert Harris
Activity
mkarbo commentedon Dec 9, 2021
I used JSON type
with partial success as a workaround for a small project.
antont commentedon Feb 18, 2022
With Postgres, you can use an array of e.g. strings or ints. I'm having it as a Set on Python side to verify that don't get duplicates, but List works too. I think they are not supported in Sqlite though.
GussSoares commentedon Feb 23, 2022
Thank you @antont !! perfectly work for postgres database
FilipeMarch commentedon Mar 20, 2022
Why this is not supported by default?
I mean, is it possible for the user to accomplish the sames as OP wants but without using
values: List[str], maybe representing it on another way that SQLModel allowsI ended up doing what @mkarbo suggested
antont commentedon Mar 21, 2022
@FilipeMarch - I guess one issue is that SQLite does not have arrays, whereas Postgres does. I'm using List but it means I can't use SQLite. Which is fine in our case, we need pg support only.
0dminnimda commentedon Oct 22, 2022
Are there any updates on this?
srausser commentedon Oct 25, 2023
Are there any updates on this?
Matthieu-LAURENT39 commentedon Oct 25, 2023
This is probably not that high on the priority list as there are workarounds, but even just having a
listcolumn use aColumn(JSON)under the hood and not needingarbitrary_types_allowedin the Pydantic config would be a massive upgrade.Although of course, it would be best to use
Column(ARRAY(...))when possible, but that's probably a bit harderbarseghyanartur commentedon Jan 16, 2024
I think the answer of mkarbo is just perfect.
JakNowy commentedon Apr 12, 2024
It's not perfect, as it introduces code redundancy. Assume you have a model for Fastapi endpoint input validation:
Then you have to redeclare those in your actual SQLModel table:
@tiangolo this would be alot cleaner to have it recognized out of the box! :)
Nikola-Milovic commentedon Oct 10, 2024
Any proposals open for this? Seems like a pretty common issue? Or is this a limitation on sqlalchemy side?
JesusMF23 commentedon Mar 22, 2025
bump, we need this, is pretty common in today's use cases
enrh commentedon May 5, 2025
Bump
pauldamian commentedon May 19, 2025
Bump.
I'm getting
ValueError: <class 'list'> has no matching SQLAlchemy typein sqlmodel's main module.VGBijpuria commentedon Jun 28, 2025
If this doesn't get added soon, I'll write a PR
wide0s commentedon Aug 7, 2025
And I need it, for my use cases. Voted.