最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - Insert manually an array of string values into a table in clickhouse db - Stack Overflow

programmeradmin1浏览0评论

I'm currently building a real-time application and using ClickHouseDB as a database. I want to insert manually or update manually the value of a field with data type Array(String).

For example: I have an array like this:

[
  {
    "order": "1",
    "option": "None of the above"
  },
  {
    "order": "2",
    "option": "Environmental Studies"
  },
  {
    "order": "3",
    "option": "STEM"
  }
]

I need to insert it into a column with data type Array(String) in the users table. Is there any way for me to insert manually or update manually?

I've tried the SQL code as follows:

ALTER TABLE users UPDATE preferred_areas = [{ "order": "1", "option": "None of the above" }, { "order": "2", "option": "Environmental Studies" }, { "order": "3", "option": "STEM" }] WHERE username = 'changpham'

But I've encountered the error mentioned in the attached image. Do you guys have no idea about it? Do you know how to fix it? Please help me to do that. Thank you so much.

I'm currently building a real-time application and using ClickHouseDB as a database. I want to insert manually or update manually the value of a field with data type Array(String).

For example: I have an array like this:

[
  {
    "order": "1",
    "option": "None of the above"
  },
  {
    "order": "2",
    "option": "Environmental Studies"
  },
  {
    "order": "3",
    "option": "STEM"
  }
]

I need to insert it into a column with data type Array(String) in the users table. Is there any way for me to insert manually or update manually?

I've tried the SQL code as follows:

ALTER TABLE users UPDATE preferred_areas = [{ "order": "1", "option": "None of the above" }, { "order": "2", "option": "Environmental Studies" }, { "order": "3", "option": "STEM" }] WHERE username = 'changpham'

But I've encountered the error mentioned in the attached image. Do you guys have no idea about it? Do you know how to fix it? Please help me to do that. Thank you so much.

Share Improve this question edited Mar 6 at 7:57 Dale K 27.5k15 gold badges58 silver badges83 bronze badges asked Mar 6 at 7:53 Orange PumpkinOrange Pumpkin 316 bronze badges 1
  • Please show the error as text not as an image – Dale K Commented Mar 6 at 7:58
Add a comment  | 

1 Answer 1

Reset to default 0

[{ "order": "1", "option": "None of the above" }, { "order": "2", "option": "Environmental Studies" }, { "order": "3", "option": "STEM" }] thi is not Array(String)

maybe better try

ALTER TABLE users UPDATE preferred_areas = ['{ "order": "1", "option": "None of the above" }', '{ "order": "2", "option": "Environmental Studies" }', '{ "order": "3", "option": "STEM" }'] 
WHERE username = 'changpham'

but please avoid too many mutations this is heavy operation which will rewrite whole data part, instead of one row

better one mutation with WHERE username IN (...) instead of multiple mutations with WHERE username=X

发布评论

评论列表(0)

  1. 暂无评论