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

Alternative implementation for JSONCodec.PlanScan #2236

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

felix-roehrich
Copy link
Contributor

The fix from #2151 just pushed the original problem from #1470 and #1691 further along. This should be a comprehensive solution; also resolves #2229.

@felix-roehrich
Copy link
Contributor Author

felix-roehrich commented Jan 21, 2025

I will add a test to prevent regression from #2229 and look at failing tests tomorrow.

@felix-roehrich felix-roehrich marked this pull request as draft January 21, 2025 00:10
@felix-roehrich
Copy link
Contributor Author

@jackc Looking at the following examples, I believe that the current scanning behavior is in inconsistent.

type Foo struct{}

var dst *Foo
err = conn.QueryRow(context.Background(), `select 'null'::jsonb`).Scan(&dst)
// err == nil
// dst == nil

var dst *Foo
err = conn.QueryRow(context.Background(), `select null::jsonb`).Scan(&dst)
// err == nil
// dst == nil

var dst Foo
err = conn.QueryRow(context.Background(), `select 'null'::jsonb`).Scan(&dst)
// err == nil
// dst == Foo{}

var dst Foo
err = conn.QueryRow(context.Background(), `select null::jsonb`).Scan(&dst)
// err == can't scan into dest[0] (col: jsonb): cannot scan NULL into *pgx_test.Foo
// dst == Foo{}

I believe either both cases of scanning Foo should error or none (or change scanning of *Foo). What is your opinion?

@felix-roehrich
Copy link
Contributor Author

I decided to revert #2151 partially. This is because this should never be necessary, as such cases would be handled by the PointerPointerScanPlan. JSON requires special care to handle the scanning of 'null'::jsonb.

@felix-roehrich felix-roehrich marked this pull request as ready for review January 22, 2025 21:34
@jackc jackc merged commit dcb7193 into jackc:master Jan 25, 2025
14 checks passed
@jackc
Copy link
Owner

jackc commented Jan 25, 2025

Thanks! sql.Scanner especially plus json has been such a pain. Hopefully, this finally resolves it.

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.

Potential regression in sql.Scanner handling when using pgx.CollectRows
2 participants