是否有postgresql SQL等效于Python的map函数

Vin*_*eel 0 sql postgresql

如何在Postgresql SQL查询中对文本数组中的每个元素应用带参数的函数

让我们说我的文本数组是

["abc-123-x", "def-123-y", "hij-234-k", "klm-232-p", "nop-3434-9", "qrs-23-p9"]
Run Code Online (Sandbox Code Playgroud)

结果应该是

[x,y,k,p,9,p9]
Run Code Online (Sandbox Code Playgroud)

a_h*_*ame 5

你需要取消数组,提取字符,然后汇总回来:

select array_agg(right(t.w, 1))
from unnest(array['abc','def','hij','klm','nop','qrs']) as t(w);
Run Code Online (Sandbox Code Playgroud)

  • @user4654:只需使用“right”而不是“left”。一般来说,一旦有了答案就改变问题被认为是不礼貌的 (2认同)