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

Include the field name in error messages when scanning structs #2225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

logicbomb
Copy link

@logicbomb logicbomb commented Jan 9, 2025

This is helpful when the order of the columns in the row is unknown (e.g. when issuing a select * query).

@logicbomb logicbomb force-pushed the improve-error-message branch from c5511eb to bdd990b Compare January 9, 2025 17:50
@jackc
Copy link
Owner

jackc commented Jan 11, 2025

The idea of including the column header is reasonable. But just the column name in parenthesis seems like it could be ambiguous. I could see people mistaking that for the name of the variable they are attempting to scan into (even though that's not actually possible in Go). Not sure what else to do without making the error message too long though.

Beyond that, why use a *string for field name instead of just a string? That leaves the possibility for nil as well as pinning the whole field descriptions slice in memory.

The tests would need to be fixed as well.

@logicbomb
Copy link
Author

logicbomb commented Jan 11, 2025 via email

@logicbomb logicbomb force-pushed the improve-error-message branch from bdd990b to 69b44c3 Compare January 11, 2025 18:24
@logicbomb
Copy link
Author

@jackc i've updated the code & tests, one test is failing locally but it looks related to my timezone settings and not the changes I'm proposing.

?       github.com/jackc/pgx/v5/testsetup       [no test files]
--- FAIL: TestConnCopyWithAllQueryExecModes (0.07s)
    --- FAIL: TestConnCopyWithAllQueryExecModes/exec (0.01s)
        copy_from_test.go:71: Input rows and output rows do not equal: [[0 1 2 abc 2010-02-03 04:05:06 -0500 EST] [<nil> <nil> <nil> <nil> <nil>]] -> [[0 1 2 abc 2010-02-03 09:05:06 +0000 +0000] [<nil> <nil> <nil> <nil> <nil>]]
    --- FAIL: TestConnCopyWithAllQueryExecModes/simple_protocol (0.01s)
        copy_from_test.go:71: Input rows and output rows do not equal: [[0 1 2 abc 2010-02-03 04:05:06 -0500 EST] [<nil> <nil> <nil> <nil> <nil>]] -> [[0 1 2 abc 2010-02-03 09:05:06 +0000 +0000] [<nil> <nil> <nil> <nil> <nil>]]
FAIL

@logicbomb logicbomb force-pushed the improve-error-message branch from 69b44c3 to d686ebb Compare January 11, 2025 19:22
@logicbomb logicbomb force-pushed the improve-error-message branch from d686ebb to 9c0ad69 Compare January 11, 2025 19:31
@logicbomb
Copy link
Author

this may be a bit painful to get through, I'm not sure how to run the full suite locally, so, i can only see test failures here. I'll make updates as I see errors coming though. Is there a way for me to run the test suite in my github account w/out needing to wait for you to press the button?

@logicbomb
Copy link
Author

logicbomb commented Jan 11, 2025

alright, i was able to get the cockroach db tests running, i see failures but seem to be unrelated to the changes in this PR

Received unexpected error:
                                ERROR: temporary tables are only supported experimentally (SQLSTATE XCEXF)
                Test:           TestLogCopyFrom/describe_exec

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.

2 participants