I need notifications to a C application on inserts to a table. The
notification funcion is listed below. My program and "Example 31-2. libpq
Example Program 2" receive the notification, but the payload message in
"PGnotify *notify->extra" is invalid.

The example code is located here:
https://www.postgresql.org/docs/current/libpq-example.html

I modified the code to include the "extra" member in the following
statement:

fprintf(stderr,
                    "ASYNC NOTIFY of '%s' received from backend PID %d:
%s\n",
                    notify->relname, notify->be_pid, *notify->extra*);

Both the example and my application core on an invalid address for "extra".
Using psql with LISTEN works correctly. My application works as expected
except for the payload message. I was unable to locate any example of how
to retrieve the payload in C. The "extra" member is a char*.

================================================

CREATE OR REPLACE FUNCTION OS_FB_UPDATE_FCNFY()
   RETURNS trigger
   LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
   notification TEXT;
BEGIN
   notification :=
      NEW.node_id      || ':' ||
      NEW.block_id     || ':' ||
      NEW.operation    || ':' ||
      NEW.update_class || ':' ||
      NEW.update_data  || ':' ||
      to_char(COALESCE(NEW.time_stamp, current_timestamp), 'MM-DD-YYY
HH24:MI:SS');

   PERFORM pg_notify('notifyondatachange', row_to_json(NEW)::text);

   RETURN NEW;

EXCEPTION
    WHEN others THEN
      RAISE WARNING '[ONSITE.OS_FB_UPDATE_FCNFY] - UDF ERROR [OTHER] -
SQLSTATE: %, SQLERRM: %', SQLSTATE, SQLERRM;
END
$BODY$;

Reply via email to