SELECT SQL statements. Because Materialize uses the PostgreSQL wire protocol, it works out-of-the-box with a wide range of SQL clients and tools that support PostgreSQL.
Overview
Materialize is wire-compatible with PostgreSQL, enabling you to query data using any PostgreSQL client library. When you query indexed views or materialized views, Materialize returns results instantly from memory.SELECT Queries
Query data in Materialize using the standardSELECT statement:
Performance Characteristics
Optimal queries:- Queries against indexed views or materialized views return maintained results from memory
- Queries that only filter, project, transform with scalar functions, and re-order indexed data
- Queries that can’t read directly from an index create ephemeral dataflows
- These dataflows are bound to the active cluster
- Materialize removes the dataflow as soon as it returns results
Cluster Selection
Control which cluster executes your queries:Connection Examples
Python (psycopg2)
Connect and query using the psycopg2 adapter:Python (psycopg3)
Psycopg3 provides similar functionality with a cleaner API:Node.js
Connect and query using node-postgres:Java (JDBC)
Connect and query using the PostgreSQL JDBC driver:psql
Connect using the PostgreSQL command-line client:Query Patterns
Point-in-Time Queries
Query the current state of a view:Filtered Queries
Apply filters to indexed data:Aggregations
Query pre-computed aggregations:Polling Queries
Because Materialize maintains incrementally updated views, you can safely poll views without impacting performance:SUBSCRIBE instead of polling.
Performance Tips
Use Indexes
Create indexes on materialized views for optimal query performance:Materialize Views
For frequently queried results, create materialized views:Dedicated Clusters
Use dedicated clusters for query workloads:Connection Pooling
Materialize is compatible with PostgreSQL connection poolers like PgBouncer:Error Handling
Connection Errors
Handle connection failures gracefully:Query Errors
Handle query errors:Client Library Guides
For language-specific guides and examples:Next Steps
Subscribe
Stream real-time updates with SUBSCRIBE
SQL Reference
Complete SELECT statement reference
Materialized Views
Create materialized views
Indexes
Create indexes for faster queries