Skip to content

Conversation

@arp242
Copy link
Collaborator

@arp242 arp242 commented Jan 5, 2026

#1219 adds more detailed errors, but the regular .Error() can still be pretty useless for queries that are longer than a few lines:

pq: invalid input syntax for type json (22P02)

This adds the position to the .Error() message:

pq: invalid input syntax for type json at position 5:8 (22P02)

Or if there's just one line it adds just the column:

pq: column "columndoesntexist" does not exist at column 8 (42703)

Downside is that it's slower:

    original    BenchmarkError-16  29751604   39 ns/op   48 B/op  1 allocs/op
    e.Position  BenchmarkError-16  16639540   75 ns/op  112 B/op  2 allocs/op
    line:col    BenchmarkError-16   3785821  315 ns/op  304 B/op  3 allocs/op

The alternative is to just add the byte offset in there:

pq: syntax error at or near ")" at offset 217 (42601)

Which is faster and arguably cleaner, but ~300ns for getting an error message still seems fine to me as pq.Error messages are typically not really in a hot path.

@arp242 arp242 force-pushed the errpos branch 2 times, most recently from 85843cf to 99c2eeb Compare January 6, 2026 09:18
#1219 adds more detailed errors, but the regular .Error() can still be
pretty useless for queries that are longer than a few lines:

	pq: invalid input syntax for type json (22P02)

This adds the position to the .Error() message:

	pq: invalid input syntax for type json at position 5:8 (22P02)

Or if there's just one line it adds just the column:

	pq: column "columndoesntexist" does not exist at column 8 (42703)

Downside is that it's slower:

        original    BenchmarkError-16  29751604   39 ns/op   48 B/op  1 allocs/op
        e.Position  BenchmarkError-16  16639540   75 ns/op  112 B/op  2 allocs/op
        line:col    BenchmarkError-16   3785821  315 ns/op  304 B/op  3 allocs/op

The alternative is to just add the byte offset in there:

	pq: syntax error at or near ")" at offset 217 (42601)

Which is faster and arguably cleaner, but ~300ns for getting an error
message still seems fine to me as pq.Error messages are typically not
really in a hot path.
@arp242 arp242 merged commit 9264ce8 into master Jan 6, 2026
25 of 26 checks passed
@arp242 arp242 deleted the errpos branch January 6, 2026 09:33
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