鉴于字符串:
'我认为 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)
这完成了我希望做的事情的基本原理,但它没有保留原始的词序。
是结合一个Postgres的方式IS DISTINCT FROM与ANY或得到同样结果的其他一些巧妙的方法?
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) 如何将texts 数组转换为UUIDs数组?
我需要join在两个表之间做一个:users和projects。
该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)
但没有一个有效:
Run Code Online (Sandbox Code Playgroud)ERROR: invalid input syntax for type uuid: ""
更新
@a_horse_with_no_name 绝对正确。最好的选择应该是使用一组 UUID。
现在的问题是我如何可以改变的阵列text到阵列uuid?
该users表当前为空(0 条记录)。
我试过了
ALTER TABLE "users" ALTER COLUMN "project_ids" SET …Run Code Online (Sandbox Code Playgroud)