From: Daniele Varrazzo Date: Sat, 28 Aug 2021 15:23:29 +0000 (+0200) Subject: Add UUID, network examples in the docs X-Git-Tag: 3.0.beta1~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d782a95047fac9a74eb5daf9e36c6583781dbe35;p=thirdparty%2Fpsycopg.git Add UUID, network examples in the docs --- diff --git a/docs/basic/adapt.rst b/docs/basic/adapt.rst index b69f1a820..91b4315c2 100644 --- a/docs/basic/adapt.rst +++ b/docs/basic/adapt.rst @@ -330,7 +330,14 @@ list may contain `!None` elements). UUID adaptation --------------- -Python `uuid.UUID` objects are adapted to PostgreSQL `UUID type`__ and back. +Python `uuid.UUID` objects are adapted to PostgreSQL `UUID type`__ and back:: + + >>> conn.execute("select gen_random_uuid()").fetchone()[0] + UUID('97f0dd62-3bd2-459e-89b8-a5e36ea3c16c') + + >>> from uuid import uuid4 + >>> conn.execute("select gen_random_uuid() = %s", [uuid4()]).fetchone()[0] + False # long shot .. __: https://www.postgresql.org/docs/current/datatype-uuid.html @@ -356,3 +363,11 @@ address types`__: :sql:`inet` and :sql:`cidr` values. .. __: https://www.postgresql.org/docs/current/datatype-net-types.html#DATATYPE-CIDR + +.. code:: python + + >>> conn.execute("select '192.168.0.1'::inet, '192.168.0.1/24'::inet").fetchone() + (IPv4Address('192.168.0.1'), IPv4Interface('192.168.0.1/24')) + + >>> conn.execute("select '::ffff:1.2.3.0/120'::cidr").fetchone()[0] + IPv6Network('::ffff:102:300/120')