Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid input syntax for type JSON [duplicate]

This query gets syntax error:

var querydb = `INSERT INTO msg_conversations VALUES (DEFAULT, ${user_id}, null, null, null, null, '{"key": "value", "unique": "' || uuid_generate_v4() || '"}'::jsonb, to_timestamp('05 Dec 2000', 'DD Mon YYYY'), to_timestamp('05 Dec 2000', 'DD Mon YYYY') )`

db.sequelize.query(querydb)
like image 611
KitKit Avatar asked Mar 06 '23 07:03

KitKit


1 Answers

first convert to text then convert to jsonb

train this tips by select statemant:

select  ('{"key": "value", "unique": "asdas'||to_timestamp( '05 Dec 2000', 'DD Mon YYYY' )||'"}' ::TEXT)::jsonb

|| only use for text type

then for your problem :

var querydb = `INSERT INTO msg_conversations VALUES (DEFAULT, ${user_id}, null, null, null, null, ('{"key": "value", "unique": "' || uuid_generate_v4() || '"}'::TEXT)::jsonb, to_timestamp('05 Dec 2000', 'DD Mon YYYY'), to_timestamp('05 Dec 2000', 'DD Mon YYYY') )`
like image 56
PersianMan Avatar answered Mar 16 '23 05:03

PersianMan