diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-31 08:46:53 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-31 08:46:53 -0400 |
| commit | f35a3f15321bd16cdc9cce69468cb50555b96a6b (patch) | |
| tree | 9017f7cc86c325906ff83cf86fbd4200eb05f94a /lib/sqlalchemy/sql | |
| parent | 77357be824095b46eb2ed3206bc555a6dacc7f30 (diff) | |
| download | sqlalchemy-f35a3f15321bd16cdc9cce69468cb50555b96a6b.tar.gz | |
clarify the Uuid datatype handles Python uuid objects by default
Change-Id: I28147bfb4eb0762e9482d4f38bc1d89355152ad4
References: #9573
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 458394870..553b07442 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -3555,6 +3555,36 @@ class Uuid(TypeEngine[_UUID_RETURN]): "native" mode enabled by default allows these types will be used on those backends. + In its default mode of use, the :class:`_sqltypes.Uuid` datatype expects + **Python uuid objects**, from the Python + `uuid <https://docs.python.org/3/library/uuid.html>`_ + module:: + + import uuid + + from sqlalchemy import Uuid + from sqlalchemy import Table, Column, MetaData, String + + + metadata_obj = MetaData() + + t = Table( + "t", + metadata_obj, + Column('uuid_data', Uuid, primary_key=True), + Column("other_data", String) + ) + + with engine.begin() as conn: + conn.execute( + t.insert(), + {"uuid_data": uuid.uuid4(), "other_data", "some data"} + ) + + To have the :class:`_sqltypes.Uuid` datatype work with string-based + Uuids (e.g. 32 character hexadecimal strings), pass the + :paramref:`_sqltypes.Uuid.as_uuid` parameter with the value ``False``. + .. versionadded:: 2.0 .. seealso:: |
