fad*_*bee 2 postgresql notify node.js pg-notify
I've read https://www.postgresql.org/docs/9.6/static/sql-notify.html and the channel name is just described as an 'identifier'.
I'm using NodeJS and pg https://www.npmjs.com/package/pg to access postgres.
If I use a lower case word in both, e.g. pg_notify('foo', ... and LISTEN foo it works. I've tested all combinations:
pg_notify LISTEN outcome
lower lower works
lower upper works
upper lower fails
upper upper fails
Run Code Online (Sandbox Code Playgroud)
Is this a bug, or is it a logical result of being an 'identifier'? (If so, should this be documented on pg_notify page?)
混乱来自于引号。单引号用于字符串,双引号用于标识符,如果您不使用混合大小写/从数字开始/或其他技巧,则可以跳到无。
当您运行pg_notify函数时,您将“foo”作为字符串参数传递,因此使用单引号,当您运行时,NOTIFY "Virtual"您使用Virtual通道名称 - 标识符,因此您需要"在此处使用。
所以当你回答自己时,改变
client.query("LISTEN 'Virtual'");
Run Code Online (Sandbox Code Playgroud)
到
client.query('LISTEN "Virtual"');
Run Code Online (Sandbox Code Playgroud)
修复了一个问题
https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS