Skip to content

How to correctly use Custom Types #2181

Answered by SennaSanzo
SennaSanzo asked this question in Q&A
Discussion options

You must be logged in to vote

I finally found my mistake, and everything is now working perfectly. I'm sharing the solution here in case someone else encounters the same issue:

In the function responsible for registering custom types, I simply forgot to register the default array type corresponding to my custom type. Although I had seen this particular example in the pgtype documentation:

func RegisterDataTypes(ctx context.Context, conn *pgx.Conn) error {
  dataTypeNames := []string{
    "foo",
    "_foo",
    "bar",
    "_bar",
  }

  for _, typeName := range dataTypeNames {
    dataType, err := conn.LoadType(ctx, typeName)
    if err != nil {
      return err
    }
    conn.TypeMap().RegisterType(dataType)
  }

  re…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SennaSanzo
Comment options

Answer selected by SennaSanzo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant