Skip to content

select * from a subquery selects all columns for all tables in the subquery #2569

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

Closed
JakeCapra opened this issue Aug 2, 2023 · 0 comments · Fixed by #2573
Closed

select * from a subquery selects all columns for all tables in the subquery #2569

JakeCapra opened this issue Aug 2, 2023 · 0 comments · Fixed by #2573
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@JakeCapra
Copy link

JakeCapra commented Aug 2, 2023

Version

1.20.0

What happened?

When selecting * from a subquery, the generated query selects all columns from all tables referenced in the subquery, not all fields selected by the subquery.

With the example provided below, the following query is generated:

SELECT t.id, authors.id, name, bio FROM (select id from authors) t

The generated query should be:

SELECT t.id FROM (select id from authors) t

If you modify the query to be:

SELECT t.* FROM (select id from authors) t;

then the generated query is correct.

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

SELECT * FROM (select id from authors) t;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/40aa4c5ab1bd5efb90024e9b35a08cdc83d28237ba2bfdc2f3ecf4ec47da4c68

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@JakeCapra JakeCapra added bug Something isn't working triage New issues that hasn't been reviewed labels Aug 2, 2023
orisano added a commit to orisano/sqlc that referenced this issue Aug 3, 2023
kyleconroy pushed a commit that referenced this issue Aug 28, 2023
… retrieving table listing (#2573)

* fix(compiler): Fix to not scan children under ast.RangeSubselect when retrieving table listing

close #2569

* test: add endtoend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
1 participant