jackc / jackc/pgx

Enhancing Custom Type Registration in pgx

Open
#2,150 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

I've created PostgreSQL extension that adds native unsigned integer data types to PostgreSQL.
I also implemented support of these types in pgx.

However implementing pgx part was a bit painful because I have need to copy & paste pgx internals code:

https://github.com/jackc/pgx/blob/2ec900454bfe65daa9648488e93f7627c26b810c/derived_types.go#L249-L262
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register.go#L241-L257


https://github.com/jackc/pgx/blob/2ec900454bfe65daa9648488e93f7627c26b810c/pgtype/register_default_pg_types.go#L5-L35
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register_default_pg_types.go#L31-L62


And there's also lack of ability to register base types:
https://github.com/jackc/pgx/blob/2ec900454bfe65daa9648488e93f7627c26b810c/derived_types.go#L158-L163

So, I have need need to implement types registration on my own:
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register.go#L66-L122

https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register.go#L124-L130

To streamline the process, I suggest we export some of these functions, such as registerDefaultPgTypeVariants and serverVersion (perhaps as a member method of conn).

Additionally, we could either adapt the LoadTypes function to support loading base types or provide a new API for base type registration.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with derived_types.go and pgtype/register_default_pg_types.go, especially the referenced registration functions and LoadTypes behavior. Compare those paths with the corresponding implementations in pgx-pg-uint128 to understand the duplicated internals and base-type limitation. Done means an agreed public registration API supports custom and base types without consumers copying pgx internals.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.