Skip to navigation
Postgres agentjob query what use a variable and if statements
06.09.23
## Example of a PSQL Postgres pgAgent job what checks the master if the salve is streaming. the result is assigned to the Postgres variable r. this variable is checked of its content "streaming", if so it will call an external API for report. ```sql DO $$ DECLARE r VARCHAR := ( SELECT state FROM pg_stat_replication WHERE client_addr = '192.168.80.242' LIMIT 1); BEGIN IF r = 'streaming' THEN RAISE NOTICE 'Streaming'; PERFORM * FROM http_post('http://api.foo.com/task', jsonb_build_object('mykey','myvalue') ); END IF; END $$; ```
https://stacktuts.com/how-to-declare-a-variable-in-a-postgresql-query
Reply
Anonymous
Information Epoch 1783198278
Think parallel.
Home
Notebook
Contact us