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
{{ message }}
Repository navigation
Return inet and cidr values as ipaddress objects by default #119
Since #43 (6.3), objects of the ipaddress module can be passed as parameters everywhere in pg and pgdb, also inline and as elements of arrays and records. Addresses and interfaces are adapted as inet, networks as cidr, as in psycopg 3.
6.3 also added the typecast functions cast_inet() and cast_cidr() in pg.cast and pgdb.cast. Like in psycopg 3, cast_inet() returns an ip_interface() for values with a prefix length and an ip_address() for other values, and cast_cidr() returns an ip_network(). They are not used by default, but can be set with:
frompg.castimportcast_cidr, cast_inet# or from pgdb.castpg.set_typecast('inet', cast_inet) # or pgdb.set_typecastpg.set_typecast('cidr', cast_cidr)
By default, inet and cidr values are still returned as strings. Making these casts the default would be a breaking change for code that works with the returned strings: comparisons like row.ip == '10.0.0.1' would silently become false, and json.dumps() or string operations would fail. So I plan to change the default only in 7.0, by adding the two casts to the default typecasts of pg and pgdb.
Notes:
macaddr and macaddr8 have no type in the standard library and stay strings (also in psycopg 3).
IPv6 addresses with a scope id (fe80::1%eth0) are accepted by Python, but not by PostgreSQL, so they cannot occur in results.
Activity