sqlc
sqlc copied to clipboard
Named parameters not recognized without space before @ char
Version
1.25.0
What happened?
When using named parameters such as @name, sqlc doesn't recognize the parameter if there's no space before the @ character.
The generated code looks as follows:
const getAuthorByName = `-- name: GetAuthorByName :one
SELECT id, name, bio FROM authors
WHERE name=@name LIMIT 1
`
func (q *Queries) GetAuthorByName(ctx context.Context) (Author, error) {
...
...
Adding a space before the @ character (for example: WHERE name = @name LIMIT 1;) solves the issue.
Relevant log output
No response
Database schema
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
SQL queries
-- name: GetAuthorByName :one
SELECT * FROM authors
WHERE name=@name LIMIT 1;
Configuration
{
"version": "2",
"sql": [{
"schema": "schema.sql",
"queries": "query.sql",
"engine": "postgresql",
"gen": {
"go": {
"out": "db"
}
}
}]
}
Playground URL
https://play.sqlc.dev/p/4d0b7efc530c30d0326be63d0471f83413361ce8e7374128728030fba43bfd70
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
This tripped me up as well. I checked the docs and didn't see this behavior documented