0
 query =
      'insert into ' +
      table +
      "( replyDate) values('" +
      event.state.session.lastMessages
        .map(function(elem) {
          return elem.replyDate
        })
        .join(',') +
      "')"

I have a table called messages which has column called replyDate. The event.state.session.lastMessages contains a list of javascript object like so : [ { eventId: '14337275205243615', incomingPreview: 'bonjour', replyConfidence: 1, replySource: 'dialogManager', replyDate: '2021-05-04T16:40:07.242Z', replyPreview: '#!builtin_single-choice-mrFFU_' } ]

I want to save in my DB the values replyDate, but i get the error:

Executing: insert into messages( replyDate) values('2021-05-07T11:33:36.721Z,2021-05-07T11:33:39.704Z,2021-05-07T11:33:42.414Z,2021-05-07T11:33:42.422Z,2021-05-07T11:33:49.454Z')
 error: la colonne « replydate » de la relation « messages » n'existe pas
Boufz
  • 3
  • 3
  • Pretty likely the column was defined with upper case characters (mistake), and you need double quotes now. – Laurenz Albe May 07 '21 at 12:24
  • Off topic: What javascript library are you using to interface with your db? You could benefit a lot from prepared statements. – Adam Jenkins May 07 '21 at 12:28
  • @LaurenzAlbe you are right, thanks. – Boufz May 07 '21 at 13:10
  • @Adam i am using the Framework Botpress – Boufz May 07 '21 at 13:11
  • Could you please share the table schema? The error message `la colonne « replydate » de la relation` suggests there is also a `replydate` column submitted instead of `replyDate`. Still seems like a spelling error, even though you provided an example object. – Peter Krebs May 07 '21 at 13:15
  • botpress has [pg](https://node-postgres.com/features/queries) as a dependency. You may want to look at [Paramaterized Queries on this page](https://node-postgres.com/features/queries) here to save yourself from SQL injection attacks. – Adam Jenkins May 07 '21 at 13:15

1 Answers1

0

If you have table names with upper case you have to enclose the table with double quotes

insert into messages( "replyDate") values('2021-05-07T11:33:36.721Z'),('2021-05-07T11:33:39.704Z'),('2021-05-07T11:33:42.414Z'),('2021-05-07T11:33:42.422Z'),('2021-05-07T11:33:49.454Z')
Philippe
  • 1,714
  • 4
  • 17