Repository navigation
WITH clause unable to find relation #2136
Description
Activity
- addedbugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed
on Mar 9, 2023 I'm not too familiar with the .g4 files but took a quick look through the parser code I could see the
deletehas the with clause - https://github.com/kyleconroy/sqlc/blob/v1.17.2/internal/engine/sqlite/parser/SQLiteParser.g4#L242-L244So I had a go at creating a new query using the with clause.
WITH abc AS ( SELECT 1 ) DELETE FROM authors WHERE id IN abc
It generates successfully - https://play.sqlc.dev/p/036d3cb198ee8ad034f18a5ee1e2f3108ec7daf38d6420ee7922cbd02a2d806b
I also ran into this today, seems to be the same issue.
Not familiar with .g4 files either, but it looks like SELECT and DELETE statements use different rules in the grammar to parse the WITH CTE, so maybe that's a clue as to why DELETE works but not SELECT.
- added and removedtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed
on Jun 7, 2023 - changed the title
[-]SQLite WITH clause unable to find relation[/-][+]WITH clause unable to find relation[/+]on Jun 7, 2023 - added 2 commits that reference this issue
on Jul 12, 2023 - added a commit that references this issue
on Jul 24, 2023 This appears to happen with the UPDATE statements, too.
- added a commit that references this issue
on Oct 13, 2025 I still have this issue with sqlite, sqlc version
v1.30.0. It logsrelation "<my_with_alias>" does not existwhen trying to insert after a with statement.
Version
1.17.2
What happened?
The following is valid when running it in the sqlite command line:
but when selecting the
sqliteengine and running it throughsqlc generateit throws the following error:If I switch the engine from
sqliteto bepostgresqlit works as expected. Which suggests the issue is just related to the sqlite implementation.Relevant log output
No response
Database schema
No response
SQL queries
Configuration
No response
Playground URL
Example of it working with postgresql engine: https://play.sqlc.dev/p/aae5b19f0a2bf4f083aa6a0156163225930d12d8ba5cc296f0b54994e2b5ccda
Same code failing when running against the sqlite engine: https://play.sqlc.dev/p/6e6dbf8511ed9ed583b7bb3eac38d57ed43c188921fd9b5b967c3213682f302b
What operating system are you using?
mac
What database engines are you using?
sqlite
What type of code are you generating?
No response