Skip to content

.* is not removed from the end of SELECT when using alias #2005

Closed
@AnotiaWang

Description

@AnotiaWang

Version

1.16.0

What happened?

When I use alias in my SELECT queries and have multiple selected source, the queries generated by sqlc will have a .* at the end of the SELECT clause.

My query:

-- name: GetUserWithRole :one
select "rs"."roles",
       "u".*
from "user" "u"
left join (
  select "ur"."user_id"                       as "id",
         array_agg("ur"."role_id")::integer[] as "roles"
  from "user_role" "ur"
  group by "ur"."user_id"
) "rs"
using ("id")
where "id" = $1::int
limit 1;

sqlc generated query:

-- name: GetUserWithRole :one
select "rs"."roles",
       u.id, u.username, u.password_hash, u.phone, u.union_id, u.created_at.*
from "user" "u"
left join (
  select "ur"."user_id"                       as "id",
         array_agg("ur"."role_id")::integer[] as "roles"
  from "user_role" "ur"
  group by "ur"."user_id"
) "rs"
using ("id")
where "id" = $1::int
limit 1

And you can see there's a u.created_at.* at the end of SELECT clause. This will lead to pq throwing pq: missing FROM-clause entry for table "created_at" .

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

No response

What operating system are you using?

Windows

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions