Add notification trigger function to DB

This commit is contained in:
D. Berge
2020-09-03 13:59:51 +02:00
parent a9a084b531
commit 0cdff4c493

View File

@@ -144,6 +144,31 @@ CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology;
COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions';
--
-- Name: notify(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.notify() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
channel text := TG_ARGV[0];
BEGIN
PERFORM pg_notify(channel, json_build_object(
'tstamp', CURRENT_TIMESTAMP,
'operation', TG_OP,
'schema', TG_TABLE_SCHEMA,
'table', TG_TABLE_NAME,
'old', row_to_json(OLD),
'new', row_to_json(NEW)
)::text);
RETURN NULL;
END;
$$;
ALTER FUNCTION public.notify() OWNER TO postgres;
--
-- Name: set_survey(text); Type: PROCEDURE; Schema: public; Owner: postgres
--