I have been playing with PostgreSQL\'s notification system and cannot for the life of my figure out why pg_notify(text, text) never works. This feature is not overly documented
I have discussed this on the PostgreSQL mailing list (http://archives.postgresql.org/pgsql-bugs/2011-03/msg00041.php) and was informed on the reasoning for the behavior.
Their answer is that "..you have to double quote relnames (listen "Test"). if you want the server not to case fold them. pg_notify takes a string, not a relname, which uses different rules." (Thanks Merlin and Tom)
This means that the following works because the channel is always forced to lower case
LISTEN ERRORCHANNEL;
NOTIFY ERRORCHANNEL, 'something!';
NOTIFY eRrorChanNel, 'something!';
If you were to add double quotes around the channel name, the case would be maintained.
So, with the following, you would receive the first notification but not the second:
LISTEN "ERRORCHANNEL";
NOTIFY "ERRORCHANNEL", 'something!';
NOTIFY "eRrorChanNel", 'something!';
Similarly, the following will work because the double quotes force the case of ERRORCHANNEL to be maintained:
LISTEN "ERRORCHANNEL";
SELECT pg_notify('ERRORCHANNEL', 'something!');
While this will not work:
LISTEN ERRORCHANNEL;
SELECT pg_notify('ERRORCHANNEL', 'something!');
In this situation ERRORCHANNEL is not in double quotes in the LISTEN command so PostgreSQL forces it to lower case. The channel parameter is of type text rather then relname so the case is left untouched in the pg_notify() function. Together the channels do not match (ERRORCHANNE != errorchannel) so the notification is never received.