Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: Scan error on column index 1, name "com_name": converting NULL to string is unsupported #668

Open
wzhsh90 opened this issue Jul 27, 2022 · 3 comments

Comments

@wzhsh90
Copy link

wzhsh90 commented Jul 27, 2022

type Company struct {
Id string db:"id" form:"id" json:"id"
ComDesc string db:"com_desc,omitempty" form:"com_desc" json:"com_desc"
ComName string db:"com_name" form:"com_name" json:"com_name"
}

i use the omitempty tag ,that is not work

@Asday
Copy link

Asday commented Jul 27, 2022

Please consider asking questions on Stack Overflow.

@VojtechVitek
Copy link
Member

VojtechVitek commented Jul 27, 2022

Or Golang Slack.

@ChristianGerdes
Copy link

Either make sure the query doesn't return rows with com_desc = null or make use of sql.NullString like so:

type Company struct {
	Id      string         `db:"id" form:"id" json:"id"`
	ComDesc sql.NullString `db:"com_desc,omitempty" form:"com_desc" json:"com_desc"`
	ComName string         `db:"com_name" form:"com_name" json:"com_name"`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants