Skip to content

fix(compiler): insert-with-select statements #4006

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dennisgsmith
Copy link

@dennisgsmith dennisgsmith commented Jun 30, 2025

Fixes #3847
Fixes #3996

I was bumping into the above issues (but for postgres) and this bug seemed to be engine agnostic. After inspecting the output with SQLCDEBUG=dumpast=1 and SQLCDEBUG=dumpcatalog=1 I found that:

  1. The CTE relation name was not in the catalog when using insert-cte-select queries.
  2. The AST WithClause was under the SelectStmt, not directly within the parent InsertStmt node.

Using the SelectStmt WithClause when it's not null resolves the issue. Please let me know if there are any changes you'd like to see. Thanks!

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang labels Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CTE doesn't get recognized by sqlc in insert statement. relation does not exist with insert using CTE
1 participant