Add MATERIALIZED support for postgres CTEs - #608
Merged
Conversation
Expose AS_MATERIALIZED alongside AS_NOT_MATERIALIZED on the postgres CommonTableExpression, and emit the MATERIALIZED keyword in the WITH clause serializer. Unit-tested without a DB to lock down the SQL shape.
go-jet
reviewed
Aug 22, 2026
| @@ -63,6 +63,7 @@ type CommonTableExpression struct { | |||
| selectTableImpl | |||
|
|
|||
Owner
There was a problem hiding this comment.
Maybe an enum would be better here instead of two bools.
go-jet
reviewed
Aug 22, 2026
|
|
||
| AS(statement jet.SerializerHasProjections) CommonTableExpression | ||
| AS_MATERIALIZED(statement jet.SerializerStatement) CommonTableExpression | ||
| AS_NOT_MATERIALIZED(statement jet.SerializerStatement) CommonTableExpression |
Owner
There was a problem hiding this comment.
AS_NOT_MATERIALIZED should accept jet.SerializerHasProjections so we can pass VALUES as well.
You can fix it for AS_MATERIALIZED also.
go-jet
reviewed
Aug 22, 2026
| SELECT n1."t.colo" AS "n1.colo" | ||
| FROM n1; | ||
| `) | ||
| } |
Owner
There was a problem hiding this comment.
Maybe add one more integration tests at ./tests/postgres just to be sure.
Owner
|
The build is failing now: # github.com/go-jet/jet/v2/sqlite
../../sqlite/with_statement.go:52:26: c.CommonTableExpression.NotMaterialized undefined (type jet.CommonTableExpression has no field or method NotMaterialized)
make: *** [Makefile:44: install-jet-gen] Error 1 |
…add integration test - Replace the two booleans on CommonTableExpression with a CTEMaterialization enum (default / forced / disabled). - Accept jet.SerializerHasProjections on AS_MATERIALIZED and AS_NOT_MATERIALIZED so VALUES statements can be passed as CTE bodies, matching AS(). - Add TestWitStatement_CTE_Materialized integration test mirroring the existing NOT MATERIALIZED one. - Update sqlite AS_NOT_MATERIALIZED to the enum (keeps all dialects building).
Author
fixed! Sorry for that. |
Owner
|
Thanks. LGMT. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expose AS_MATERIALIZED alongside AS_NOT_MATERIALIZED on the postgres CommonTableExpression, and emit the MATERIALIZED keyword in the WITH clause serializer. Includes simple unit-test.
Once this is merged, could we cherry-pick it over to the pgx branch as well? I rely pgx for a project.