sqlc
sqlc copied to clipboard
`SELECT FROM` queries return template error
Version
1.13.0
What happened?
(Preface: I know I am being a little stupid)
In queries.sql I wrote the following query:
-- name: listlegalsets :many
SELECT FROM legalsets LIMIT 500;
Whilst writing out a large number of basic queries I missed out the Asterisk (*) from the above query. The error that I got from running sqlc generate
was the following:
✘ theoa@Theos-MacBook-Pro ~/GolandProjects/awesomeProject2/data sqlc generate
# package query
error generating code: template: queryCode.tmpl:51:79: executing "queryCodeStd" at <.Ret.DefineType>: error calling DefineType: no type for QueryValue:
I understand that the error is a simple one as a result of bad SQL but is there any chance this error can be made clearer? (5 mins of my life I wasted to my own stupidity)
I would much prefer if it generated an error message that determined WHICH query was bad:
error generating code: template: error calling DefineType: no type for QueryValue: QueryName: XXX
Relevant log output
error generating code: template: queryCode.tmpl:51:79: executing "queryCodeStd" at <.Ret.DefineType>: error calling DefineType: no type for QueryValue:
Database schema
create table legalsets (
id uuid not null primary key default gen_random_uuid(),
name text not null unique
);
SQL queries
-- name: listlegalsets :many
SELECT FROM legalsets LIMIT 500;
Configuration
version: 1
packages:
- path: "query"
name: "query"
engine: "postgresql"
schema: "schema.sql"
queries: "queries.sql"
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The funny thing is that the query statement you wrote is perfeclty legal in Postgres. From the docs:
The list of output expressions after SELECT can be empty, producing a zero-column result table.
This is not valid syntax according to the SQL standard.
PostgreSQL allows it to be consistent with allowing zero-column tables.
So the error seems to be that you wrote something correct and the generator could not handle it. However, from your description I think that you expect this select statement to be an error and want to be notified.
If (and that's a big if) that generator error would be corrected, you would end up with a query that returns a list of empty structs. I don't see a use case for this (at least not in sqlc). OTOH, the current error message is not helpful to a user, but returning an error when a legal select statement is submitted is not cool, either.
So before fixing this, we need to decide what the expected outcome should be.
As @akutschera, this is a completely valid SQL query. It will return an empty row. This shouldn't result in an error.