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

Query or QueryRows does not return ErrNoRows error when no record is found #2251

Open
cdong8812 opened this issue Feb 9, 2025 · 1 comment
Labels

Comments

@cdong8812
Copy link

cdong8812 commented Feb 9, 2025

Describe the bug
Query or QueryRow method does not return ErrNoRows error when using SQL left joins another table with where filter

To Reproduce
Sample SQL to reproduce the bug:

query := SELECT f.id, f.name FROM foo f LEFT JOIN bar b ON f.id = b.foo_id WHERE f.id = 123

Expected behavior
Query or QueryRow returns ErrNoRows error when no record is found

Actual behavior
Query or QueryRow returns no error when no record is found

Version

  • Go: 1.22.3
  • PostgreSQL: 12.2
  • pgx: v5.7.2
@cdong8812 cdong8812 added the bug label Feb 9, 2025
@jackc
Copy link
Owner

jackc commented Feb 17, 2025

First, Query will never return ErrNoRows. A query returning no rows is a perfectly valid result. Only QueryRow has the expectation of a non-empty result.

Second, the fact that your query has a left join is irrelevant to pgx. It sends the query and reads the result. The actual type of query doesn't matter. I suggest trying your query in psql. It probably is not returning what you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants