jeffwidman / sqlalchemy-postgresql-materialized-views Goto Github PK
View Code? Open in Web Editor NEWA SQLAlchemy recipe for managing PostgreSQL Materialized Views:
Home Page: http://jeffwidman.com/blog/847/
License: MIT License
A SQLAlchemy recipe for managing PostgreSQL Materialized Views:
Home Page: http://jeffwidman.com/blog/847/
License: MIT License
Following the method of Jeff Widman to generate materialized views with SQLAlchemy; the Column
types from the selectables are parsed roughly like:
selectable = select([MyObject])
table = Table('new_table', MetaData())
for c in selectable.c:
table.append_column(Column(c.name, c.type, primary_key=c.primary_key))
If I print the variable table, I get the correct column types:
Table('new_table', MetaData(bind=None), Column('column1', String(length=20), table=<new_table>), Column('id', UUIDType(length=16), table=<new_table>, primary_key=True, nullable=False), Column('jsonb_column', JSONB(astext_type=Text()), table=<new_table>), Column('record_created', DateTime(), table=<new_table>), schema=None)
However, when I query the MV class. The column types are changed to type InstrumentedAttribute
:
sqlalchemy.inspect(MyMaterializedView.column1)
sqlalchemy.orm.attributes.InstrumentedAttribute at 0x7fe420fd4ba0
Why are the types not correct? And how can I fix this?
(BTW, I'm on Pyramid which might differ slightly from Flask.)
Hello,
I read your blog post, thanks for your work it was an excellent read. I was thinking of reusing your code for managing my materialized views in Python. Are you aware of any existing effort to publish this as a dedicated module, or to integrate it in SQLAlchemy directly (for example as a dialect extension)?
Follow-up question, what do you think would be the roadblocks to such an integration, technically and otherwise?
Best regards,
Olivier
HI Jeff,
This is a very nice article, thank you for taking your time to write it. Looking at the code, I was wondering if the materialized view needs to be created manually in advance in the database or it will be automatically created by the model.
I cannot figure out where (and how) is the execution of 'CREATE MATERIALIZED VIEW ....'.
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.