Zit*_*ong 11 postgresql activerecord ruby-on-rails
我想使用UUID作为标识符,提供前8位数字以确定它是否存在于数据库中.
通常我可以毫无问题地做到这一点:
select * from TABLE where id = 'e99aec55-9e32-4c84-aed2-4a0251584941'::uuid
但这给了我错误:
select * from TABLE where 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%@"
Run Code Online (Sandbox Code Playgroud)
有没有办法在postgresql中查询UUID类型的前n位数?
poz*_*ozs 11
由于您正在搜索uuids 的最高位,因此您可以实际使用between(因为uuid比较在PostgreSQL中定义良好):
...
where some_uuid between 'e99aec55-0000-0000-0000-000000000000'
and 'e99aec55-ffff-ffff-ffff-ffffffffffff'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6977 次 |
| 最近记录: |