PostgreSQL:json类型的输入语法无效

时间:2018-10-04 08:17:41

标签: postgresql

请帮助我检查此查询命令。它得到语法错误:

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)

我使用NodeJS。

提前谢谢!

1 个答案:

答案 0 :(得分:3)

首先转换为文本,然后转换为jsonb

通过选择statemant训练此技巧:

In [209]: arr
Out[209]: 
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
       [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
       [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]])

In [210]: np.random.seed(0)

In [211]: select_random_windows(arr, number_of_windows=3, window_size=(2,4))
Out[211]: 
array([[[41, 42, 43, 44],
        [51, 52, 53, 54]],

       [[26, 27, 28, 29],
        [36, 37, 38, 39]],

       [[22, 23, 24, 25],
        [32, 33, 34, 35]]])

select ('{"key": "value", "unique": "asdas'||to_timestamp( '05 Dec 2000', 'DD Mon YYYY' )||'"}' ::TEXT)::jsonb 仅用于文本类型

然后解决您的问题:

||