On 11/09/2015 03:52 PM, Jeff Widman wrote:
> A couple of quick questions about Postgres Materialized Views--searched,
> but found very little:
> 
> I've got a few values that are fairly expensive to calculate, so I'd
> like to pre-calculate the results. It's fine if the the data is stale
> for a few hours, so I'd like to use Postgres Materialized Views:
> 
> 1) How do I create a Materialized View using SQLAlchemy? 

connection.execute("CREATE MATERIALIZED VIEW ....")

alternatively you can adapt the recipe at
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views to
support the "MATERIALIZED VIEW" syntax supported by your database.


> I checked the docs, and all I could find is how to reflect an
> already-created materialized view. All my other DDL is managed by
> SQLAlchemy in my app, so for simplicity I'd rather handle the
> materialized view definition using SQLAlchemy as well.
> 
> 2) How do I query this materialized view?

a view is like any other table-oriented structure in the database.  a
Table metadata object or Table-mapped ORM class that uses the name and
columns of this view will suffice.  I've added a short example of a
declarative mapping against the custom view object to the above example.





> 
> 3) Is there a special method for refreshing? 
> Or should I just do /db.engine.execute("REFRESH MATERIALIZED VIEW
> view_name CONCURRENTLY") /?
> 
> Cheers,
> Jeff
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> To post to this group, send email to sqlalchemy@googlegroups.com
> <mailto:sqlalchemy@googlegroups.com>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to