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

Fix result type decl for nullable :one queries #77

Merged
merged 1 commit into from
Dec 16, 2022
Merged

Fix result type decl for nullable :one queries #77

merged 1 commit into from
Dec 16, 2022

Conversation

jschaf
Copy link
Owner

@jschaf jschaf commented Dec 16, 2022

Previously, if a query returned a single nullable column, pggen would return the correct type *string, but only because we took the address of the input.

Bad code:

var item string
if err := row.Scan(&item); err != nil {
	return &item, fmt.Errorf("query StringAggFirstName: %w", err)
}
return &item, nil

Fixed code:

var item *string
if err := row.Scan(&item); err != nil {
	return item, fmt.Errorf("query StringAggFirstName: %w", err)
}
return item, nil

Fixes #75.

Previously, if a query returned a single nullable column, pggen would
return the correct type *string, but only because we took the address
of the input.

Bad code:

	var item string
	if err := row.Scan(&item); err != nil {
		return &item, fmt.Errorf("query StringAggFirstName: %w", err)
	}
	return &item, nil

Fixed code:

	var item *string
	if err := row.Scan(&item); err != nil {
		return item, fmt.Errorf("query StringAggFirstName: %w", err)
	}
	return item, nil

Fixes #75.
@jschaf jschaf merged commit 4e47108 into main Dec 16, 2022
@jschaf jschaf deleted the joe/one-ptr branch June 18, 2023 04:06
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

Successfully merging this pull request may close these issues.

Nullability seemingly not respected when only one string column is returned
1 participant