Skip to content

Naming columns in FROM clause fails #2225

Open
@hugosjoberg

Description

@hugosjoberg

Version

1.17.2

What happened?

I tried renaming a column in a from clause. Running the query in postgres is successful however running it in sqlc fails.

Relevant log output

/query.sql:15:2: column "age" does not exist

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   numeric PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- GetAuthor :one
with mp AS (
    SELECT * FROM
        (values (30, 0), (23, 1)) x(age, id)
)

SELECT
	mp.age as years,
	a.name
FROM
    authors as a
    LEFT JOIN mp on mp.id = a.id;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/a4c15c684f4abd40e5fda3e7dfa8148163ac3a3cf093d0164f3ed2306d44f728

What operating system are you using?

Linux

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