Skip to content

Add MATERIALIZED support for postgres CTEs - #608

Merged
go-jet merged 2 commits into
go-jet:masterfrom
philon123:master
Aug 30, 2026
Merged

Add MATERIALIZED support for postgres CTEs#608
go-jet merged 2 commits into
go-jet:masterfrom
philon123:master

Conversation

@philon123

Copy link
Copy Markdown

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.

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.
@@ -63,6 +63,7 @@ type CommonTableExpression struct {
selectTableImpl

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an enum would be better here instead of two bools.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread postgres/with_statement.go Outdated

AS(statement jet.SerializerHasProjections) CommonTableExpression
AS_MATERIALIZED(statement jet.SerializerStatement) CommonTableExpression
AS_NOT_MATERIALIZED(statement jet.SerializerStatement) CommonTableExpression

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AS_NOT_MATERIALIZED should accept jet.SerializerHasProjections so we can pass VALUES as well.
You can fix it for AS_MATERIALIZED also.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

SELECT n1."t.colo" AS "n1.colo"
FROM n1;
`)
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add one more integration tests at ./tests/postgres just to be sure.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@go-jet

go-jet commented Aug 24, 2026

Copy link
Copy Markdown
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).
@philon123

Copy link
Copy Markdown
Author

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

fixed! Sorry for that.

@go-jet

go-jet commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Thanks. LGMT. 👍

@go-jet
go-jet merged commit 86e2357 into go-jet:master Aug 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants