ITADN
go-pg/pg/Issues

Insert boolean type field with false value.

#1863Closedrive-n 创建于 2021-04-04
R
rive-ncommented
I have struct: ```golang type ms_backend_customuser struct { tableName struct{} `pg:"ms_backend_customuser"` Password string LastLog time.Time `pg:"last_login"` CreatedAt time.Time `pg:"created_at"` ModifiedAt time.Time `pg:"modified_at"` Email string `pg:"email"` FirstName string `pg:"first_name"` LastName string `pg:"last_name"` SuRights bool `pg:"su_rights" sql:",notnull,default:false"` Admin bool `pg:"admin_rights" sql:",notnull,default:false"` Active bool `pg:"active" sql:",notnull,default:true"` } ``` Here i want to insert default values, like: CreatedAt, ModifiedAt and etc. pg default and sql default are not working for me. So that's how i am doing default in code: ```golang func (user *ms_backend_customuser) BeforeInsert (ctx context.Context) (context.Context, error) { log.Println("Inserting current time.") user.CreatedAt = time.Now().UTC() user.ModifiedAt = time.Now().UTC() user.LastLog = time.Now().UTC() return ctx, nil } ``` Now - new problem. There is no information about insertion of boolean false. I tryed a lot, but ORM always inserts "DEFAULT", not "false": `INSERT INTO "ms_backend_customuser" ("password", "last_login", "created_at", "modified_at", "email", "first_name", "last_name", "su_rights", "admin_rights", "active") VALUES ('pbkdf2_sha256$216000$5TS34IT+6RxtH/MP$893T++yKDNf4KEIvoEy60t7Z/vYWbWz6fOYsjjySBM8=', '2021-04-04 15:20:41.044193+00:00:00', '2021-04-04 15:20:41.044193+00:00:00', '2021-04-04 15:20:41.044193+00:00:00', 'riven4@riven.com', DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "first_name", "last_name", "su_rights", "admin_rights", "active"` As you can see i am trying `sql` in annotations. I tryed pg too. Nothing works for me. Is that a BUG?
关闭于 2021-04-15 9 条评论