go-rel / go-rel/rel

Missing row on execution

Open
#371 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
786
Forks
61
Avg merge
4d 11h
Merged PRs (30d)
2

Description

When I run the following query:
``` go
var query = rel.
Select("c.id", "c.created_time", "c.updated_time", "c.archived", "c.name", "c.description", "^MAX(n.updated_time) last_note_dated", "^AVG(n.score) avg_score").
From("contacts as c").
JoinWith("LEFT JOIN", "notes as n", "n.object_id", "c.id", where.Eq("n.archived", false)).
Where(where.Eq("c.archived", false)).
Group("c.id", "c.created_time", "c.updated_time", "c.archived", "c.name", "c.description")
```

The query must return two records, but instead it returns only one.
The missing records is the one which has no notes associated. If I copy the query from the instrumentation log and run it manually against the db, it returns two records.

However if I modify the query to (see `as`):
``` go
var query = rel.
Select("c.id", "c.created_time", "c.updated_time", "c.archived", "c.name", "c.description", "^MAX(n.updated_time) as last_note_dated", "^AVG(n.score) as avg_score").
From("contacts as c").
JoinWith("LEFT JOIN", "notes as n", "n.object_id", "c.id", where.Eq("n.archived", false)).
Where(where.Eq("c.archived", false)).
Group("c.id", "c.created_time", "c.updated_time", "c.archived", "c.name", "c.description")
```

I have got the following error (similar to #370):
```
sql: Scan error on column index 6, name \"last_note_dated\": unsupported Scan, storing driver.Value type string into type *time.Time", err:(*errors.errorString)(0xc0003f7940)
```

Looks like something bad is going on when queries got executed. I am probably thinking to quit `go-rel` as it constantly prevents me from progressing my project.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported query and comparing its execution with the SQL shown in the instrumentation log. Inspect query execution and result scanning, using the related behavior in #370 as context. Done means the query returns both contacts, including the one without notes, and the aggregate fields scan without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.