Skip to content

Nested WITH doesn't work #2226

Closed
Closed
@hugosjoberg

Description

@hugosjoberg

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

Activity

added
bugSomething isn't working
triageNew issues that hasn't been reviewed
on Apr 23, 2023
kyleconroy

kyleconroy commented on Oct 24, 2023

@kyleconroy
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kyleconroy@hugosjoberg

        Issue actions

          Nested WITH doesn't work · Issue #2226 · sqlc-dev/sqlc