Skip to content

Support range and multirange types #140

Open

Description

@Cito

PyGreSQL has no support for range types (PostgreSQL 9.2) and multirange types (PostgreSQL 14). Values are returned as strings like '[1,5)', 'empty' or '{[1,5),[7,9)}', and there is no Python type to pass them as parameters.

psycopg 3 has Range and Multirange classes with casts and adapters for the built-in types (int4range, int8range, numrange, daterange, tsrange, tstzrange and their multiranges) and for user-defined range types.

Proper support would need:

  • a Range class (bounds, inclusivity, empty, unbounded) and a Multirange class, in pg and pgdb,
  • casts that convert the bounds with the cast of the subtype (from pg_range), also for user-defined range types and as elements of arrays and records,
  • adaptation of these objects as parameters, also inline and in arrays.

Returning Range objects instead of strings by default would break existing code, so this is planned for 7.0. Until then, a typecast function can be registered with set_typecast().

Activity

  1. added this to the 7.0 milestone on Nov 22, 2026
  2. modified the milestones: 7.0, 6.4 on Nov 23, 2026
  3. Cito commented on Nov 23, 2026

    @Cito
    MemberAuthor

    I moved this to 6.4, since most of it can be added without breaking existing code: the Range and Multirange classes, their adaptation as parameters (also inline and as elements of arrays and records), and casts for the built-in and user-defined range types that can be enabled explicitly, like the ipaddress support in 6.3. Range values will still be returned as strings by default. Making the new casts the default would be a breaking change, so that stays in 7.0, see #152.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions