JSONB
I am trying to define a type in a struct with JSONB and it seems the struct isn't available with pgtype.
import ( "github.com/jackc/pgx/v5/pgtype" )
type User struct {
ID int json:"id"
UID pgtype.UUID json:"uid"
Email string json:"email"
FirstName string json:"first_name"
LastName string json:"last_name"
PhoneNumber *string json:"phone_number"
Properties pgtype.JSONB json:"properties,omitempty" db:"properties"
}
I get a undefined: pgtype.JSONB error. Am I importing that correctly? I can see the file in the github repo and it seems it should be available but it looks like only JSONBCodec is available.
I use []byte correspond to JSONB type and it works well
pgtype.JSONB doesn't exist in v5. You shouldn't need it. You can use json.RawMessage if you want the JSON text.