pgx icon indicating copy to clipboard operation
pgx copied to clipboard

JSONB

Open astabeno opened this issue 10 months ago • 2 comments

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.

astabeno avatar Mar 09 '25 11:03 astabeno

I use []byte correspond to JSONB type and it works well

armistcxy avatar Mar 11 '25 08:03 armistcxy

pgtype.JSONB doesn't exist in v5. You shouldn't need it. You can use json.RawMessage if you want the JSON text.

jackc avatar Mar 15 '25 19:03 jackc