简体   繁体   English

AWS redshift join 与 function 返回错误

[英]AWS redshift join with a function returns an error

I am trying to join two different tables by using a left function - for reference ( https://docs.aws.amazon.com/redshift/latest/dg/r_LEFT.html ) And it throws an error saying "invalid operation" i wish the error message was a little more helpful. I am trying to join two different tables by using a left function - for reference ( https://docs.aws.amazon.com/redshift/latest/dg/r_LEFT.html ) And it throws an error saying "invalid operation" i希望错误消息更有帮助。 If i remove the left function then it works but i need to make it work with a function as i didn't see any limitations on docs.. I am not sure why it doesn't work with a function as Any advice on how to solve it?如果我删除左边的 function 那么它可以工作,但我需要让它与 function 一起工作,因为我没有看到对文档的任何限制。我不知道为什么它不能与 ZC1C425264C17A94F14 的建议一样工作解决这个问题?

select id from state
LEFT JOIN city c ON lower(left(c.segmentation_name::text, '-4'::integer)) = lower(state.name::text)

left supports only positive integers as a second argument. left仅支持正整数作为第二个参数。 Try right(c.segmentation_name::text, 4) instead.请尝试right(c.segmentation_name::text, 4)

If you want all but the last four characters, then use:如果您想要除最后四个字符之外的所有字符,请使用:

from state s left join
     city c 
     on substring(lower(c.segmentation_name::text), 1, len(c.segmentation_name::text) - 4) = lower(state.name::text)

The conversions to text look really awkward. text的转换看起来真的很尴尬。 Perhaps this is sufficient:也许这就足够了:

from state s left join
     city c 
     on substring(lower(c.segmentation_name), 1, len(c.segmentation_name) - 4) = lower(state.name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM