postgresql-ocaml icon indicating copy to clipboard operation
postgresql-ocaml copied to clipboard

Example for notification usage

Open geohuz opened this issue 3 years ago • 4 comments

Is there any example code for pg notification?

geohuz avatar Jan 21 '22 10:01 geohuz

See usage in prompt.ml: dump_notification

dboris avatar Jan 27 '22 02:01 dboris

Thanks, @dboris, yes, prompt.ml and prompt_gtk.ml contain some example code.

mmottl avatar Jan 27 '22 03:01 mmottl

I'm sorry to come back this later, I'm afraid the mechanism in the "dump_notifcation" is not the same as the async listen and notify on channel. As stated in https://www.postgresql.org/docs/16/libpq-notify.html , which is basically clients run PQexec(conn, "LISTEN testChannel"), and on the server or other end point you execute the select pg_notify('testChannel', 'Hi there').

PostgreSQL offers asynchronous notification via the LISTEN and NOTIFY commands. A client session registers its interest in a particular notification channel with the LISTEN command (and can stop listening with the UNLISTEN command). All sessions listening on a particular channel will be notified asynchronously when a NOTIFY command with that channel name is executed by any session. A “payload” string can be passed to communicate additional data to the listeners.

geohuz avatar Aug 17 '24 04:08 geohuz

Sorry for the late reply. I don't have time to investigate this right now, but please feel free to propose any changes that will make the code consistent with the expected functionality.

mmottl avatar Nov 05 '24 05:11 mmottl