You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document sqlc behavior for queries with JOINs #643
Hi. Thanks for a great project. The idea is really promising and fresh for the Go ecosystem!
One thing wasn't clear for me from the existing documentation and examples:
How sqlc handles relations and complex queries with JOINs, does it still uses flat structures for the output or it somehow reuses and embeds structs that represent a single table.
After going through existing issues I found out that sqlc goes with the simplest approach and generates a flat structure for every query even a complex one with a JOIN.
I think you should explicitly document it or add an example with a JOIN, because maybe not only me was looking for something like that.
Reacted by Alex Chaplianka, Jesús García Crespo, Jacob Block, Emanuel Quimper, Ivan Koptiev, Hosh, koodimetsa, Philip Scott, Lever, Lars Graubner and 20 more
I'm trying to create a query with LEFT JOIN, but a query parameter with 13 entries is generated, but my query only has 11 entries.
Then I get the error: "sql: expected 11 arguments, got 13"
My query:
SELECT sqlc.embed(u), sqlc.embed(r)
FROM users u
LEFT JOIN user_roles ur ON u.id = ur.user_id
LEFT JOIN roles r ON ur.role_id = r.id
WHERE ((u.created_at BETWEEN ? AND ?) OR (? = '' AND ? = '') OR (? IS NULL AND ? IS NULL))
AND ((u.is_active = ?) OR (? = '') OR (? IS NULL))
ORDER BY u.created_at DESC
LIMIT ?
OFFSET ?;
Activity
fr3fou commentedon Nov 5, 2020
Were the docs added? I'm wondering the same thing
kylecarbs commentedon Apr 26, 2021
@kyleconroy I'd love to work on this. Before I do, I'd love your thoughts on doing the following:
Currently, this would generate a struct like:
I'm wondering if we could embed existing structs instead... like:
This would enable complex cross-table queries sharing structs.
kyleconroy commentedon Aug 28, 2021
@kylecarbs Please see #363 for a discussion about embedding structs. It's a bit more complicated that it seems.
kyleconroy commentedon Aug 28, 2021
This is doubly important now that #983 has been merged.
arshbot commentedon May 10, 2022
Bump - and progress here?
cholazzzb commentedon May 11, 2023
Bump again - any updated?
KaviiSuri commentedon May 22, 2023
now that we have sqlc.embed merged, why is it not documented in the docs? I'd love to help out if needed, but we need to add documentation for it
KenanHH commentedon Jul 13, 2023
bump?
DeedleFake commentedon Aug 22, 2023
It's not in the main documentation, but there's a quick summary of the new
sqlc.embed()in the changelog.kyleconroy commentedon Sep 22, 2023
Sorry for the lack of documentation. We added a dedicated section for this in the last release.
https://docs.sqlc.dev/en/stable/howto/embedding.html
rssistemasitu commentedon Feb 17, 2024
I'm trying to create a query with LEFT JOIN, but a query parameter with 13 entries is generated, but my query only has 11 entries.
Then I get the error:
"sql: expected 11 arguments, got 13"My query:
Generated parameter:
My classes:
It appears that
sqlcis generating an incorrect amount of query inputs.Please, can you help me?