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
Hi,
I'm seeing similar errors with a few variations on this join. Is this a related issue, or shall I raise a seperate one?
SELECT f, b
FROM foo f
JOIN bar b ON b.id = f.id
WHERE f.id = $1;
query.sql:6:8: column "f" does not exist
SELECT foo, bar
FROM foo
JOIN bar ON bar.id = foo.id
WHERE foo.id = $1;
query.sql:6:8: column "foo" does not exist
SELECT f.id, b.title
FROM foo f
JOIN bar b ON b.id = f.id
WHERE f.id = $1;
query.sql:6:8: column "id" does not exist
There are two issues at play. The first is that sqlc doesn't currently support SELECT foo FROM foo. This is the reason the first two queries error. Do you have example Go code you use to scan those results?
The third query fails due to incorrect alias support, and should be easier to fix.
Unfortunately I don't have much more than the examples provided and the code generated by sqlc - I've just started playing around with it today for potential use in future.
My hope was that I'd get something like the below struct generated, but I'd be happy to have any way to extract all columns from both tables:
typeSomeRowstruct {
FooFooBarBar
}
In the meantime I've worked around it by explicitly selecting each field I care about, which works perfectly fine:
SELECTfoo.id, bar.titleFROM foo
JOIN bar ONbar.id=foo.idWHEREfoo.id= $1;
but I'd be happy to have any way to extract all columns from both tables
You can get that behavior by using *:
SELECT*FROM foo
JOIN bar ONbar.id=foo.idWHEREfoo.id= $1;
Selecting the table name (SELECT foo FROM foo) returns a single column with a composite type ROW(id). Composite types have poor support in lib/pq. The value passed to Scan is tuple represented as a string (e.g. (id)). I haven't found a library that properly handles these values. SELECT * has much better support.
Now that you mention it I did try SELECT *, but both tables have an id field, and sqlc expands the * out to something like SELECT id, title, id (which postgres rejects due to ambiguity)
Activity
kyleconroy commentedon Dec 24, 2019
@tgascoigne I'm going to assume that the foo and bar tables look like this
tgascoigne commentedon Dec 25, 2019
Yep, that's equivalent to what I'm using
kyleconroy commentedon Dec 25, 2019
There are two issues at play. The first is that sqlc doesn't currently support
SELECT foo FROM foo. This is the reason the first two queries error. Do you have example Go code you use to scan those results?The third query fails due to incorrect alias support, and should be easier to fix.
tgascoigne commentedon Dec 25, 2019
Thanks for the quick response :)
Unfortunately I don't have much more than the examples provided and the code generated by sqlc - I've just started playing around with it today for potential use in future.
My hope was that I'd get something like the below struct generated, but I'd be happy to have any way to extract all columns from both tables:
In the meantime I've worked around it by explicitly selecting each field I care about, which works perfectly fine:
kyleconroy commentedon Dec 25, 2019
You can get that behavior by using
*:Selecting the table name (
SELECT foo FROM foo) returns a single column with a composite typeROW(id). Composite types have poor support inlib/pq. The value passed toScanis tuple represented as a string (e.g.(id)). I haven't found a library that properly handles these values.SELECT *has much better support.tgascoigne commentedon Dec 25, 2019
Now that you mention it I did try
SELECT *, but both tables have anidfield, and sqlc expands the*out to something likeSELECT id, title, id(which postgres rejects due to ambiguity)kyleconroy commentedon Dec 26, 2019
🤦♂ yeah,
*expansion should be smart enough to generate columns that do not collide.kyleconroy commentedon Feb 10, 2020
@tgascoigne This has now be fixed in master. The following two queries should now work