1

I have used the pgjdbc-ng for Postgresql listen and notify.

I'd like to perform notify in the loop.

My example code:

FOR idx  IN 0..3 LOOP
   PERFORM pg_notify('q_event','test');
END LOOP;

I expect this using listen:

test test test

But I just receive one text.

I want to know it is possible. If then, teach me please. Thank you for your answer.

Bongousse
  • 28
  • 4

1 Answers1

1

Consecutive notifies with the same payload are treated as a single one. Try this:

FOR idx  IN 0..3 LOOP
   PERFORM pg_notify('q_event', format('test %s', idx));
END LOOP;

A client listening on the channel q_event will receive four messages (from 0 to 3).

klin
  • 112,967
  • 15
  • 204
  • 232