jackc / pgx

PostgreSQL driver and toolkit for Go
MIT License
10.86k stars 846 forks source link

Providing a type with the name `event_trigger` to `conn.LoadType()` results in an "unknown typtype" error. #2175

Open rubenhazelaar opened 4 days ago

rubenhazelaar commented 4 days ago

Describe the bug Providing a type with the name event_trigger to conn.LoadType() results in an "unknown typtype" error. Following the logic of conn.LoadType(), an OID of 3838 and typtype=p are found, which seems to refer to a native Postgres type.

To Reproduce Steps to reproduce the behavior:

  1. Set up the environment with the provided DATABASE_URL.
  2. Define a type named event_trigger.
  3. Call conn.LoadType() with event_trigger.
  4. Observe the "unknown typtype" error.

If possible, please provide a runnable example such as:

package main

import (
    "context"
    "log"
    "os"

    "github.com/jackc/pgx/v5"
)

func main() {
    conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close(context.Background())

    poolConfig.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
        dataType, err := conn.LoadType(ctx, "event_trigger")
            if err != nil {
                return err // Error "unknown typtype" returned here
            }
            conn.TypeMap().RegisterType(dataType)

        return nil
    }

        // ...
}

Expected behavior The type should be loaded without causing an "unknown typtype" error.

Actual behavior The application fails to load the type and logs an "unknown typtype" error.

Version

Additional context This issue is probably due to an (unintended) naming conflict with a native Postgres type. It would be helpful for other users to be aware that such conflicts can cause this error. However perhaps there also is something which can be done differently here, not sure though.