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 all, I ran into an issue trying to write a query using views and sqlc.embed. I am not sure if what I want to do is supported, but it "almost" works, and would be very useful.
What I noticed, is that if I have a table, say foos, and a view on that table, view_foos, sqlc will let me sqlc.embed(foos) a result from a query using view_foos.
This seems to work if and only if the sqlc.embed is the only thing selected in the query, as soon as I try to add another column, embed, anything else, the parser fails.
-- name: TestQuery :manySELECTsqlc.embed(foos), 1as test
FROM view_foos;
For simplicity, I just projected a random value as column, but this repros with anything (for example, a column from a joined table).
If this worked, it would be a great way to write a query that returns the same codegen type on a view of a real table. The use-case I had was soft-deletion, I have a real table, and a view on that table that excludes soft-deleted rows. If this worked, I could write queries that return my original type instead of my soft-deleted view type (which is identical other than in name). Maybe there is another way to achieve what I want, for example an override in sqlc.yaml?
Thanks!
Relevant log output
query.sql:2:9: edited query syntax is invalid: syntax error at or near ","
Database schema
CREATETABLEfoos (
a INT
);
CREATEVIEWview_foosASSELECT*FROM foos;
SQL queries
-- name: TestQuery :many-- working versionSELECTsqlc.embed(foos)
FROM view_foos;
-- name: TestQuery :many-- broken versionSELECTsqlc.embed(foos), 1as test
FROM view_foos;
Version
1.28.0
What happened?
Hi all, I ran into an issue trying to write a query using views and
sqlc.embed
. I am not sure if what I want to do is supported, but it "almost" works, and would be very useful.What I noticed, is that if I have a table, say
foos
, and a view on that table,view_foos
, sqlc will let mesqlc.embed(foos)
a result from a query usingview_foos
.This seems to work if and only if the
sqlc.embed
is the only thing selected in the query, as soon as I try to add another column, embed, anything else, the parser fails.Working version:
https://play.sqlc.dev/p/028ba999022e364f9bb968af1a8cc72440093e5c47e7f6ba72ec5f2692fa4a46
Failing version:
https://play.sqlc.dev/p/bb8cd9fff4fe52f1a1e4dce1dc576c583f24e3fbe89bf385972e1c9c0df2e5a9
For simplicity, I just projected a random value as column, but this repros with anything (for example, a column from a joined table).
If this worked, it would be a great way to write a query that returns the same codegen type on a view of a real table. The use-case I had was soft-deletion, I have a real table, and a view on that table that excludes soft-deleted rows. If this worked, I could write queries that return my original type instead of my soft-deleted view type (which is identical other than in name). Maybe there is another way to achieve what I want, for example an override in sqlc.yaml?
Thanks!
Relevant log output
query.sql:2:9: edited query syntax is invalid: syntax error at or near ","
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/bb8cd9fff4fe52f1a1e4dce1dc576c583f24e3fbe89bf385972e1c9c0df2e5a9
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: