相关疑难解决方法(0)

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

鉴于字符串:

'我认为 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万
查看次数

IS DISTINCT FROM 可以以某种方式与 ANY 或 ALL 结合吗?

是结合一个Postgres的方式IS DISTINCT FROMANY或得到同样结果的其他一些巧妙的方法?

select count(*)
from (select 'A' foo union all select 'Z' union all select null) z
where foo <> any(array[null, 'A']);

 count
-------
     1
(1 row)

select count(*)
from (select 'A' foo union all select 'Z' union all select null) z
where foo is distinct from any(array[null, 'A']);  

ERROR:  syntax error at or near "any"
LINE 3: where foo is distinct from any(array[null, 'A']);
                                   ^
Run Code Online (Sandbox Code Playgroud)

postgresql null postgresql-9.3

14
推荐指数
3
解决办法
1843
查看次数

将文本数组转换为 UUID 数组

如何将texts 数组转换为UUIDs数组?

我需要join在两个表之间做一个:usersprojects

users表有一个名为的数组字段,project_ids其中包含作为文本的项目 ID。

projects表有一个名为 的 UUID 字段id

我最初的想法是一个查询看起来像:

SELECT * FROM projects
JOIN users ON
projects.id = ANY(users.project_ids)
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为users.project_ids不是,UUID所以我试过:

projects.id = ANY(users.project_ids::uuid[])
Run Code Online (Sandbox Code Playgroud)

乃至:

projects.id = ANY(ARRAY[users.project_ids]::uuid[])
Run Code Online (Sandbox Code Playgroud)

但没有一个有效:

ERROR: invalid input syntax for type uuid: ""
Run Code Online (Sandbox Code Playgroud)

更新

@a_horse_with_no_name 绝对正确。最好的选择应该是使用一组 UUID。

现在的问题是我如何可以改变的阵列text到阵列uuid

users表当前为空(0 条记录)。

我试过了

ALTER TABLE "users" ALTER COLUMN "project_ids" SET …
Run Code Online (Sandbox Code Playgroud)

postgresql join cast array uuid

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

标签 统计

postgresql ×3

array ×2

cast ×1

join ×1

null ×1

parse ×1

postgresql-9.3 ×1

sorting ×1

uuid ×1