Views are virtual tables based on the result of a SQL query. They simplify complex queries, improve security, and in the case of materialized views, can significantly boost performance.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/drizzle-team/drizzle-orm/llms.txt
Use this file to discover all available pages before exploring further.
Standard views
Query-based views
Create a view from a Drizzle query:- PostgreSQL
- MySQL
- SQLite
SQL-based views
Define views with raw SQL for complex queries:Querying views
Use views like regular tables:Existing views
Reference views created outside Drizzle:Use
.existing() to tell Drizzle this view already exists and shouldn’t be created during migrations.PostgreSQL materialized views
Materialized views store query results physically, improving performance for expensive queries:Basic materialized view
Materialized view with configuration
Materialized view without data
Create the view structure without populating it:Use
withNoData() to create the view structure quickly. Populate it later with REFRESH MATERIALIZED VIEW.Refreshing materialized views
Materialized views need manual refresh to update their data:PostgreSQL view options
Security options
Prevents leaking data through user-defined functions in WHERE clauses
Executes view with the privileges of the user calling it, not the view owner