Skip to content

Redesign connect() in pgdb (and pg) #114

Open

Description

@Cito

The signatures and semantics of pgdb.connect() are hard to use and partly ambiguous (see the discussion in #77):

  • The dsn format host:dbname:user:password:opt cannot contain a port; the port can only be passed as part of host (host:port).
  • When both dsn and keyword parameters are given, they override each other in a non-obvious way.
  • Additional keyword arguments are converted to a connection string, which is passed as dbname. This fails when database is a URI, None values are passed as 'None', and bytes values as their Python representation.
  • In C, connections are made with PQconnectdbParams with a fixed set of keywords, so arbitrary connection parameters cannot be passed directly (see Use PQconnectdbParams instead of PQsetdbLogin #26).

Proposal: a clear signature like in other drivers (host, port, dbname/database, user, password, plus arbitrary libpq keywords), with keyword values passed directly via PQconnectdbParams instead of a connection string, None values ignored, and a conninfo string or URI as an alternative to the keywords. This would be a breaking change, so it is planned for 7.0.

Activity

  1. modified the milestones: 7.0, 6.4 on Nov 22, 2026
  2. Cito commented on Nov 23, 2026

    @Cito
    MemberAuthor

    I moved this to 6.4, since most of the proposal can be added without breaking existing code: passing arbitrary libpq connection parameters as keywords directly via PQconnectdbParams (ignoring None values), and accepting a conninfo string or URI as an alternative. The old host:dbname:user:password:opt format of the dsn parameter and the ambiguous combinations with keyword parameters will then emit a DeprecationWarning. Removing them is left for 7.0. The details of the new signature are still to be decided.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions