PostgreSQL Cheat Sheet/Create materialized view

Persist query results for faster reads.

Section: Views, Functions, Triggers, and Extensions

Create materialized view

sql
sql
CREATE MATERIALIZED VIEW daily_sales AS
SELECT date_trunc('day', created_at) AS day, sum(total_amount) AS revenue
FROM orders
GROUP BY 1;
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Views, Functions, Triggers, and Extensions
Create database
Create a new database in the cluster.
OpenIn sheetsql1 tag match
Create schema
Create a namespace for objects.
OpenIn sheetsql1 tag match
Create database with owner
Create a database with explicit owner and template.
OpenIn sheetsql1 tag match
Create table
Create a basic table with primary key and defaults.
OpenIn sheetsql1 tag match
Create identity column
Use a SQL-standard identity column instead of serial.
OpenIn sheetsql1 tag match
Create login role
Create a role that can log in.
OpenIn sheetsql1 tag match