Is it possible to add native postgresql UUID type support for creating table over model with CreateTable func?
https://www.postgresql.org/docs/9.6/static/datatype-uuid.html
Did you try https://github.com/google/uuid or https://github.com/satori/go.uuid?
I tried https://github.com/satori/go.uuid - it supports UUIDv5.
For CreateTable you can add field annotation
type Article struct {
Id uuid.UUID `sql:",type:uuid"`
}
Later go-pg can be improved to treat [16]byte as uuid (but I am not sure if it should be)...
Thank you very much!
I am new to go and go pg. Here is what I had learnt the hard way
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
import (
pg "github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
uuid "github.com/satori/go.uuid"
)
You need now tell go-pg to correctly map your struct to postgres sql type. if you don't pay attention to this details especially usage of 'pg' and 'type:uuid. most of the information available on net refers 'sql' and using will result into creation of table with type 'bytea' instead of 'uuid'
you need to use 'pg' as a package reference not _'sql'_
type Story struct {
Id uuid.UUID `pg:",pk,type:uuid default uuid_generate_v4()"`
Title string
AuthorId uuid.UUID `pg:",type:uuid DEFAULT uuid_generate_v4()"`
}
Most helpful comment
For
CreateTableyou can add field annotationLater go-pg can be improved to treat
[16]byteas uuid (but I am not sure if it should be)...