Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql notify #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions postgresql_in_qgis.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,34 @@ CREATE INDEX ON nom_du_schema.nom_de_la_table USING GIST (geom);
Si on souhaite automatiser la création des indexes pour toutes les tables qui n'en ont pas, on peut utiliser une fonction, décrite dans la partie [Fonctions utiles](./utils.md)

Continuer vers l'[Import des données dans PostgreSQL](./import_data.md)

### Utiliser les notifications PostgreSQL

Dans les propriétés de la couche vecteur, activer les notifications avec le message `chef_lieu`.

```sql
DROP VIEW IF EXISTS buffer_chef_lieu;
CREATE VIEW buffer_chef_lieu AS
SELECT
id, nom,
ST_BUFFER(geom, 1000) AS geom
FROM chef_lieu;

CREATE OR REPLACE FUNCTION qgis_notify()
RETURNS trigger AS
$BODY$
BEGIN
PERFORM pg_notify('qgis', 'chef_lieu');
RETURN NULL;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

CREATE TRIGGER qgis_trigger
AFTER INSERT OR UPDATE
ON chef_lieu
FOR EACH ROW
EXECUTE PROCEDURE qgis_notify();

```