相关疑难解决方法(0)

如何将 JSON 数组转换为 Postgres 数组?

我有一个data类型的列,json其中包含这样的 JSON 文档:

{
    "name": "foo",
    "tags": ["foo", "bar"]
}
Run Code Online (Sandbox Code Playgroud)

我想将嵌套tags数组转换为连接字符串 ( 'foo, bar')。array_to_string()从理论上讲,使用该函数很容易做到这一点。但是,此功能不接受json输入。所以我想知道如何将这个 JSON 数组变成 Postgres 数组(类型text[])?

postgresql array postgresql-9.3 json

97
推荐指数
4
解决办法
28万
查看次数

在MYSQL中存储数组?

我用谷歌搜索过。我不断收到与名为“serialize”的 PHP 函数有关的答案。我不会使用 PHP,所以遗憾的是该解决方案对我不起作用。

我之前使用过 NoSQL 数据库(我认为是 MongoDB),我基本上定义了一个集合

images [
    {"title": "Cute puppy", "file"="cute.png", "tags": ["cute", "puppy", "summer", "pool"]}
]
Run Code Online (Sandbox Code Playgroud)

我想在标签列的一行中存储多个值(老实说,我不知道我说得对不对,刚刚开始搜索MySQL)

+------------+----------+--------------------------+
| title      | file     | tags                     |
+------------+----------+--------------------------+
| Cute Puppy | cute.png | cute,puppy,summer,pool   |
+------------+----------+--------------------------+
Run Code Online (Sandbox Code Playgroud)

我唯一的想法是,如果我使用 MySQL 来读取行,然后用逗号分隔标签,这很可能会起作用,但我可能会在百万。

我的问题是,如果你想在一列中存储多个值,MySQL 是一个不错的选择吗?

mysql nosql

7
推荐指数
1
解决办法
7万
查看次数

如何从json数组中删除对象?

我的表:

CREATE TABLE items (
    id BIGINT PRIMARY KEY NOT NULL,
    name VARCHAR,
    images json
);
Run Code Online (Sandbox Code Playgroud)

图片格式:

[
  {
    "id": "owner",
    "full": "<url>",
    "thumb": "<url>"
  },
  {
    "id": "note_0",
    "full": "<url>",
    "thumb": "<url>"
  },
  {
    "id": "note_1",
    "full": "<url>",
    "thumb": "<url>"
  },
  {
    "id": "note_2",
    "full": "<url>",
    "thumb": "<url>"
  }
]
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西:

UPDATE items SET images = delete(images, 'note_1');
Run Code Online (Sandbox Code Playgroud)

postgresql postgresql-9.3 json

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

json ×2

postgresql ×2

postgresql-9.3 ×2

array ×1

mysql ×1

nosql ×1