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

Nested WITH doesn't work #2226

Closed
hugosjoberg opened this issue Apr 23, 2023 · 1 comment
Closed

Nested WITH doesn't work #2226

hugosjoberg opened this issue Apr 23, 2023 · 1 comment

Comments

@hugosjoberg
Copy link

Version

1.17.2

What happened?

When a WITH is nested it doesn't work. The query works when running the query directly against postgres but fails when running in SQLC.

Relevant log output

/query.sql:9:1: relation "summary" does not exist

Database schema

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

SQL queries

-- name: GetAuthor :one
WITH person AS(
    WITH summary AS(
        WITH mb AS(
            select
                *
            from authors
        )
        SELECT
            bio
        FROM mb
        )
    SELECT
       count(*)
    FROM summary
)

select * from person;

Configuration

No response

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@hugosjoberg hugosjoberg added bug Something isn't working triage New issues that hasn't been reviewed labels Apr 23, 2023
@kyleconroy kyleconroy added 📚 postgresql 🔧 golang 💻 linux and removed triage New issues that hasn't been reviewed labels Jun 6, 2023
kyleconroy added a commit that referenced this issue Oct 18, 2023
kyleconroy added a commit that referenced this issue Oct 18, 2023
* test: Add case for #2132
* test: Add case for #2152
* test: Mark case for #2152
* test: Add case for #2187
* test: Add case for #2226
* test: Add case for #2364
* test: Add case for #2386
* test: Add case for #2538
* test: Add case for #2644
* test: Add case for #2731
@kyleconroy
Copy link
Collaborator

This is fixed in v1.23.0 by enabling the database-backed query analyzer. We added a test case for this issue so it won’t break in the future.

You can play around with the working example on the playground

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

No branches or pull requests

2 participants