Creating views in PostGIS
In a database, a view is a stored query. Every time that you open it, the query is run and fresh results are generated. To use views as layers in QGIS takes a couple of steps.
Getting ready
For this recipe, you'll need a query that returns results containing a geometry. The example that we'll use here is the query from the Joining tables in databases recipe where attributes were joined 1:1 between the census polygons and the population CSV.
How to do it…
The SQL method is described as follows:
In Database | DB Manager, open SQL Window.
Write a query; in this example, this is the join query that was written in the previous exercise. If you want to see it right away but not necessarily retain it, check the Load as new layer checkbox near the bottom:
SELECT * FROM census_wake2000 as a JOIN census_wake2000_pop as b ON a.stfid = b."STFID";
Now, execute the query by clicking on the Execute (F5) button:
After executing the query, to load it to the map check the Load as new layer...