PostgreSQL has a native UUID datatype, so when you use SQLAlchemy's UUID, it 
maps to a real PG UUID datatype, not BYTEA.

as for sqlalchemy_utils.UUIDType, we dont maintain that package here so you'd 
need to look at their source code.

Overall if you want complete "UUID mapped to any arbitrary binary datatype on 
any platform unambiguously", code it yourself, using the example at 
https://docs.sqlalchemy.org/en/20/core/custom_types.html#backend-agnostic-guid-type
 as a guide.  that example currently uses CHAR(32), but you can change it to 
use BYTEA/BINARY with appropriate changes.   sqlalchemy_utils likely got their 
UUID type from an older version of this example.

On Tue, Oct 10, 2023, at 8:35 PM, Sam S wrote:
> I noticed that mysql's BINARY(16) datatype can get read into sqlalchemy's 
> UUID() no problem, but if it is postgres' BYTEA datatype, then it fails. I 
> created a reproducible example at this gist: 
> https://gist.github.com/sss-ng/1283c85d1010264132985156c148439b
> 
> If someone could help me, I would like to know how i can read a binary UUID 
> into model in postgres using sqlalchemy.
> 
> Thank you
> Sam
> 
> 
> -- 
> 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/56e11560-7a36-4a2b-9364-8a5f4201946fn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/56e11560-7a36-4a2b-9364-8a5f4201946fn%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/c3a15e41-b9b4-41ea-95db-ab9402fc51f1%40app.fastmail.com.

Reply via email to