hey there -

a list[str] can be lots of different kinds of datatype, like JSON, custom array 
types, and PG ARRAY, which is specific to PostgreSQL.  so for non-obvious 
datatypes like this you indicate them explicitly:

from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy import String
col: Mapped[list[str]] = mapped_column(ARRAY(String))


hoping this is clear from the doc at 
https://docs.sqlalchemy.org/en/20/orm/declarative_tables.html#using-annotated-declarative-table-type-annotated-forms-for-mapped-column
 which illustrates several of the mapped_column() with explicit datatype and 
also states "If the `mapped_column()` 
<https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.mapped_column>
 construct indicates an explicit type as passed to the `mapped_column.__type` 
<https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.mapped_column.params.__type>
 argument, then the given Python type is disregarded".




On Sun, Feb 19, 2023, at 7:21 PM, Samuel Killin wrote:
> I'm struggling to define a SQLAlchemy column for a postgres string array 
> using the new declarative mapping pattern in 2.0.
> 
> I would expect something like this to work:
> *my_col: Mapped[list[str]] = mapped_column()*
> 
> However, this throws with:
> *sqlalchemy.exc.ArgumentError: Could not locate SQLAlchemy Core type for 
> Python type list[str] inside the 'my_col' attribute Mapped annotation
*
> Any ideas?
> 
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/3b0e17b9-15cc-43b8-9c3c-e3ce73c71c85n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/3b0e17b9-15cc-43b8-9c3c-e3ce73c71c85n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/ef087ba8-bd2c-4524-84ad-31aededf1cba%40app.fastmail.com.

Reply via email to