相关疑难解决方法(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万
查看次数

如何保留未嵌套数组中元素的原始顺序?

鉴于字符串:

'我认为 PostgreSQL 很漂亮'

我想对该字符串中找到的单个单词进行操作。本质上,我有一个单独的,我可以从中获取单词详细信息,并希望在此字典上加入该字符串的未嵌套数组。

到目前为止,我有:

select word, meaning, partofspeech
from unnest(string_to_array('I think that PostgreSQL is nifty',' ')) as word
from table t
join dictionary d
on t.word = d.wordname;
Run Code Online (Sandbox Code Playgroud)

这完成了我希望做的事情的基本原理,但它没有保留原始的词序。

相关问题:
PostgreSQL unnest() with element number

postgresql parse sorting array

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

如何从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万
查看次数

标签 统计

postgresql ×3

array ×2

json ×2

postgresql-9.3 ×2

parse ×1

sorting ×1