db icon indicating copy to clipboard operation
db copied to clipboard

Insert and Save Queries incompatible with postgres default values (v3)

Open kipply opened this issue 5 years ago • 1 comments

An insert or save query (that goes to an insert) will pass through all columns, and using a null value if that column had no input.

This causes failures with postgres in the form of either;

  1. the column that has a default is set to nil
  2. the column that has a default yields an error because it has a not null clause that should be protected by a default

will test with upper v4 soon

kipply avatar Nov 16 '20 21:11 kipply

Hello @kipply,

Is this case something that could be solved by using the omitempty option? That word tells upper to ignore the field when it has a zero value:

type User struct {
  ID int `db:"id,omitempty"`
}

Let me know if your case is different.

xiam avatar Nov 28 '20 18:11 xiam