Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AnotiaWang opened this issue Dec 24, 2022 · 1 comment · Fixed by #2576
Closed

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

AnotiaWang opened this issue Dec 24, 2022 · 1 comment · Fixed by #2576

Comments

@AnotiaWang
Copy link

AnotiaWang commented Dec 24, 2022

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

@AnotiaWang AnotiaWang added bug Something isn't working triage New issues that hasn't been reviewed labels Dec 24, 2022
@zaneli
Copy link
Contributor

zaneli commented Feb 5, 2023

I found workaround.
Try to unquote "u".* to u.*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants