Skip to content

NOTIFY query - syntax error at or near "$1" #1258

Closed

Description

@DrLou

What is the syntax error in this query?
Have tried a variety of quoting options - (have escaped the comma, thinking this was the problem?)

One of you will look at this and say 'ah ha!'

pool.connect(function(err, client, done) {
if(err) {
  // return console.error('error fetching client from pool', err);
  return console.error(err);
  }
  // PostgreSQL NOTIFY
  client.query("NOTIFY bottle\, $1", ["hope you get this message"], function(err, result) {
    done(err);
    
    if(err) {
      return console.error('error running query', err);
    }
    console.log('Successful NOTIFY');
  });
});

Activity

  1. charmander commented on Apr 7, 2017

    @charmander
    Collaborator

    NOTIFY statements can’t be parameterized. From https://www.postgresql.org/docs/current/static/sql-notify.html:

    To send a notification you can also use the function pg_notify(text, text). The function takes the channel name as the first argument and the payload as the second. The function is much easier to use than the NOTIFY command if you need to work with non-constant channel names and payloads.

    So:

    pool.query("SELECT pg_notify('bottle', $1)", ["hope you get this message"])

    See also #539.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions