Closed
Description
Field gets invalid type which in my case causes runtime error when scanning into struct:
sql: Scan error on column index 6, name "orders_count": sql/driver: couldn't convert 14 into type bool
I also managed to reproduce it in the sqlc playground:
query.sql
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
CREATE TABLE books (
id BIGSERIAL PRIMARY KEY,
author_id BIGSERIAL NOT NULL
REFERENCES authors(id),
title text NOT NULL
);
-- name: GetAuthorsWithBooksCount :many
SELECT *, (
SELECT COUNT(id) FROM books
WHERE books.author_id = id
) AS books_count
FROM authors;
Noticed interesting thing: if i remove AS statement (column alias) it will give this field name Exists
type GetAuthorsWithBooksCountRow struct {
ID int64
Name string
Bio sql.NullString
Exists bool
}
I think it may help fix this bug.