Question: Is there any way to create common PostGIS views (e.g. buffers, intersections, differences) by using script-created dialog boxes. A GUI for doing spatial analysis based on PostGIS would be quite helpful for users with no SQL skills.

Example 'Buffer':

[![enter image description here](https://i.stack.imgur.com/z41e2.png)](https://i.stack.imgur.com/z41e2.png)

[![enter image description here](https://i.stack.imgur.com/U20kS.png)](https://i.stack.imgur.com/U20kS.png)

```
CREATE VIEW test_schema.buffer_bus_stops AS
SELECT
    row_number() over() AS gid,
    ST_Buffer(geom, 100)::geometry(Polygon, /*SRID*/) AS geom
FROM test_schema.bus_stops;

```

Answer: 
You can run any SQL on a connected database. Create a script:

```
##Run SQL=name
##dbname=string 
##mysql=string 
outputs_QGISPOSTGISEXECUTESQL_1=processing.runalg('qgis:postgisexecutesql', dbname,mysql)

```

When run, this will give you a dialogue box where you can add the database name and the SQL statement. 

![](https://i.stack.imgur.com/bim8N.png)
If I understand correctly, you want a "wizard" to let you write SQL?

There is a plugin called **PostGIS Query Builder** which does just that... see [cheatsheet here](https://geogear.wordpress.com/postgisquerybuilder-v1-6-cheatsheet/). It seems to allow gradual building up of queries, and allows creation of views as an option.

Not used it in too much depth, but it sounds like what you're after.

See further down for details on installation... it didn't work 'out of the box', not for me anyway.

---

[![postgis query builder](https://i.stack.imgur.com/j3VBo.png)](https://i.stack.imgur.com/j3VBo.png)

---

[![postgis query builder](https://i.stack.imgur.com/sw1SE.png)](https://i.stack.imgur.com/sw1SE.png)

---

Note, if you're on Ubuntu you might need to install Qt Postgres bindings using 

```
sudo apt-get install libqt4-sql-psql

```

or you'll get a "Driver not loaded" message. See [this issue on the Github issues page](https://github.com/enricofer/postgisQueryBuilder/issues/15).

I have no idea if it works on Windows/Mac.