gpt4 book ai didi

ruby-on-rails - 如何查询 postgres 的 UUID

转载 作者:行者123 更新时间:2023-11-29 11:14:44 24 4
gpt4 key购买 nike

我想使用 UUID 作为标识符,提供前 8 位数字以确定它是否存在于数据库中。

通常我可以毫无问题地做到这一点:

从表中选择 *,其中 id = 'e99aec55-9e32-4c84-aed2-4a0251584941'::uuid

但这给了我错误:

select * from TABLE 其中 id LIKE 'e99aec55%@'::uuid

错误:

ERROR:  invalid input syntax for uuid: "e99aec55%@"
LINE 1: select * from TABLE where id LIKE 'e99aec55...
^
Query failed
PostgreSQL said: invalid input syntax for uuid: "e99aec55%@"

有没有办法在 postgresql 中查询 UUID 类型的前 n 位数字?

最佳答案

由于您正在搜索 uuid 的最高位,因此您实际上可以使用 between(因为 uuid 比较在PostgreSQL):

...
where some_uuid between 'e99aec55-0000-0000-0000-000000000000'
and 'e99aec55-ffff-ffff-ffff-ffffffffffff'

关于ruby-on-rails - 如何查询 postgres 的 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33549747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com