简体   繁体   中英

postgresql — create a materialized view by inserting data from multiple tables

I have multiple tables containing the same columns. i want to build an aggregated table containing the data from all these tables. I'm wondering if materialized view can do this. If so, what's the query like? I have no problem getting and filtering data from one table, but I have no idea if it's possible to do it with multiple tables

the structure of my db currently looks like this

db
|
| - table1 
| - table2
| - table3

and I'm trying to get data from all of them and put into a view (and update when content in table# changes)

Is there a way to do this?

This is what the UNION operator is for. You should be able to do something like this:

SELECT col1, col2 FROM table1 UNION SELECT col1, col2 FROM table2;

There's a tutorial for UNION here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM