sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Resolving references to CTE Columns fails

Open simonklee opened this issue 1 year ago • 0 comments

Version

1.27.0

What happened?

Resolving references to multiple CTE's with arguments fails.

This is a duplicate of #3219, but 3219 has been closed even thought the issue still persists and the relevant PR is not merged.

PR to fix this issue: https://github.com/sqlc-dev/sqlc/pull/3220

Relevant log output

sqlc generate failed.
# package 
query.sql:5:28: table alias "t1_ids" does not exist

Database schema

CREATE TABLE t1
(
    id SERIAL NOT NULL PRIMARY KEY
);

SQL queries

-- name: CTERef :one
WITH t1_ids AS (
    SELECT id FROM t1
)
SELECT * FROM t1_ids WHERE t1_ids.id = sqlc.arg('id');

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}
​

Playground URL

https://play.sqlc.dev/p/9048b486f822c300301650867612e42bef8f8d512dfd12d84ad3a4cd210f4ef7

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

simonklee avatar Sep 06 '24 08:09 simonklee