Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Nullable types for computed columns? #1030

Unanswered
gabrielhora asked this question in Q&A
Discussion options

Hi there,

I'm trying to come up with a solution for having nullable types for computed columns.
I know I can override table column types via overrides in sqlc.yaml, is there a way to do the same for queries?

This is a simple example, min and max may return null. How can I deal with this in sqlc?

const test = `-- name: Test :one
select min(age)::int as min_age, max(age)::int as max_age from my_table
`
type TestRow struct {
	MinAge int32
	MaxAge int32
}
func (q *Queries) Test(ctx context.Context) (TestRow, error) {
	row := q.db.QueryRowContext(ctx, test)
	var i TestRow
	err := row.Scan(&i.MinAge, &i.MaxAge)
	return i, err
}

Thanks a lot for your time.

You must be logged in to vote

Replies: 1 comment

Comment options

no response? may i know why?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /