1

Im trying to append new object into json array field

UPDATE phone_messages SET messages = JSON_ARRAY_APPEND(messages, '$', CAST('?' AS JSON)) WHERE charId = ? AND number = ? this is SQL I'm using but its giving me error (You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JSON)).

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Jasmina
  • 11
  • 2
  • hi, is the cast needed? perhaps append a string without casting – jspcal Jan 10 '22 at 23:21
  • without casting object is stored as json string, its not similar to other objects in array (in this case I also need to JSON.stringlfy(data) before doing SQL. without that I'm getting [object][object] as string in column) – Jasmina Jan 10 '22 at 23:26
  • 1
    Possible duplicate: https://stackoverflow.com/questions/42185598/1064-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds – Bill Karwin Jan 10 '22 at 23:40
  • You have another issue with your code that is not causing an error yet: don't put a parameter placeholder `?` inside quotes. – Bill Karwin Jan 10 '22 at 23:41

0 Answers0