Skip to content

copy from doesn't work with UUIDs #262

@matthewmueller

Description

@matthewmueller

Wasn't able to get uuid's working. Doesn't seem to work as a UUID, a string or a slice of bytes.

Here's the error I'm seeing:

ERROR: incorrect binary data format (SQLSTATE 22P03)

I took a peak around to see if I could get it working, but it seems like COPY IN needs very specific values. I think there's a mismatch between the postgres uuid type and the encoded uuid string.

Here's the code I'm using:

// ...
events := [][]interface{}{}
for _, ti := range times {
	events = append(events, []interface{}{uuid.NewV4(), ti})
}

// bulk insert
_, err = tx.CopyFrom(pgx.Identifier{"events"}, []string{"task", "time"}, pgx.CopyFromRows(events))
if err != nil {
	log.WithError(err).Error("Unable to copy in events")
	return
}

tx.Commit()

FWIW, I was able to get this working with pq, so there might be something to pull from there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions