-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(pg): add virtual generated columns support for pg 18 #4934
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
base: main
Are you sure you want to change the base?
feat(pg): add virtual generated columns support for pg 18 #4934
Conversation
namhtpyn
commented
Sep 21, 2025
- Add virtual mode support for PostgreSQL generated columns
- Update schema serializer to handle both virtual and stored generated columns
- Modify SQL generator to support VIRTUAL keyword in generated column statements
- Add comprehensive tests for virtual generated columns
- Update type definitions and interfaces for virtual generated column configuration
- Ensure backward compatibility with existing stored generated columns
- Add virtual mode support for PostgreSQL generated columns - Update schema serializer to handle both virtual and stored generated columns - Modify SQL generator to support VIRTUAL keyword in generated column statements - Add comprehensive tests for virtual generated columns - Update type definitions and interfaces for virtual generated column configuration - Ensure backward compatibility with existing stored generated columns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for virtual generated columns in PostgreSQL 18, expanding beyond the existing stored generated columns functionality. The change enables developers to create virtual computed columns that are calculated on-the-fly rather than physically stored.
Key changes:
- Enhanced generated column configuration to support both virtual and stored modes
- Updated SQL generation to produce VIRTUAL keyword for virtual columns
- Added comprehensive test coverage for virtual generated column scenarios
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
drizzle-orm/type-tests/pg/generated-columns.ts | Added comprehensive type tests for virtual generated columns |
drizzle-orm/src/pg-core/columns/common.ts | Enhanced generatedAlwaysAs method to accept mode configuration |
drizzle-kit/tests/pg-generated.test.ts | Added test cases for virtual generated columns and mode transitions |
drizzle-kit/src/sqlgenerator.ts | Updated SQL generation to support VIRTUAL keyword |
drizzle-kit/src/serializer/pgSerializer.ts | Modified serializer to handle virtual/stored mode properly |
drizzle-kit/src/serializer/pgSchema.ts | Updated schema validation to accept virtual and stored types |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
lastName: varchar('last_name', { length: 255 }), | ||
email: text('email').notNull(), | ||
fullName: text('full_name').generatedAlwaysAs( | ||
sql`concat_ws(first_name, ' ', last_name)`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The concat_ws function call has incorrect parameter order. The separator should be the first parameter, but here 'first_name' is passed as the separator instead of ' '. It should be concat_ws(' ', first_name, last_name)
.
Copilot uses AI. Check for mistakes.
{ mode: 'virtual' }, | ||
).notNull(), | ||
upperName: text('upper_name').generatedAlwaysAs( | ||
sql` case when first_name is null then null else upper(first_name) end `, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] There are extra spaces at the beginning and end of the SQL template literal. Remove the leading and trailing spaces for consistency: sql
case when first_name is null then null else upper(first_name) end``.
Copilot uses AI. Check for mistakes.