Repository navigation
Support ipaddress objects as parameters (#43) - #118
Merged
Merged
Conversation
Arrays of types that PyGreSQL does not know, e.g. of enums or of inet, got the simple type "text" instead of "text[]", so DB.insert() and DB.update() sent the Python list as a string. Such array types now get the simple type "text[]", and type names like "_inet" passed to format_query() are recognized as arrays as well. Types that are only named like arrays, but are not arrays, are still mapped to "text".
Objects of the ipaddress module were only adapted when passed as separate parameters in pg, where they were converted to strings. As inline parameters in pg and as parameters in pgdb, they raised an InterfaceError. Now addresses and interfaces are adapted as inet and networks as cidr, as in psycopg 3, also as elements of arrays and records. The values are escaped, since the scope id of an IPv6 address may contain quotes.
The new functions cast_inet() and cast_cidr() in pg.cast, also available in pgdb.cast, cast inet and cidr values to objects of the ipaddress module, as in psycopg 3: inet values with a prefix length to interfaces, other values to addresses, and cidr values to networks. They are not used by default, since these values are still returned as strings, but can be set with set_typecast().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objects of the
ipaddressmodule could only be passed as separate parameters inpg, where they were converted to strings. As inline parameters inpgand as parameters inpgdb, they raised anInterfaceError. This adapts them in all paths, as in psycopg 3, and adds opt-in typecast functions for returning them. Closes #43.Main changes:
inet, networks ascidr, inpg(format_query()andquery_formatted()withinline=True) and inpgdb, also as elements of arrays and records. The values are escaped, since the scope id of an IPv6 address may contain quotes.inet,cidror enums) got the simple typetextinstead oftext[], soDB.insert()andDB.update()sent the Python list as a string. They now gettext[], also as type names like_inet. This changes whatDB.get_attnames()returns for such columns.cast_inet()andcast_cidr()inpg.castandpgdb.cast. They are not used by default, soinetandcidrvalues are still returned as strings, but can be set withset_typecast(). Making them the default would be a breaking change, which I will propose separately for 7.0.