sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.64k stars 813 forks source link

No result table columns when using named subselect with join #1522

Open peteole opened 2 years ago

peteole commented 2 years ago

Version

1.12.0

What happened?

running sqlc generate on a select statement that uses a subselect that includes a join operation results in an empty columnset

Relevant log output

# package sqlc
sql-queries/projects.sql:159:1: empty edit contents

Database schema

CREATE TABLE public.projects (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    name character varying(100) NOT NULL
);
CREATE TABLE public.project_saves (
    user_id uuid NOT NULL,
    project_id uuid NOT NULL,
    created_at timestamp without time zone DEFAULT now()
);

SQL queries

SELECT r.*
FROM (
        project_saves
        JOIN projects
        ON project_saves.project_id = projects.id
    ) r;

Configuration

version: "1"
packages:
  - path: "sqlc"
    name: "sqlc"
    engine: "postgresql"
    schema: "schema.sql"
    queries: "sql-queries"

Playground URL

https://play.sqlc.dev/p/7a3d51abd4191695fa4412ad377a93f3e6f764b5630dea0cb4e5051390f1d9ea

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

kyleconroy commented 1 year ago

This now compiles but the generated query is invalid

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