如何在UUID中查询postgres [英] How to query UUID for postgres

查看:528
本文介绍了如何在UUID中查询postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to use UUID as an identifier, provide the first 8 digits to find out if it exists in the database.

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

normally I can do this without a problem:

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

但这会给我错误:

从表中选择*,例如id'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中的前U个数字以获取UUID类型?

Is there a way to query first n digits for a UUID type in postgresql?

推荐答案

由于您要搜索 uuid s的最高位,您实际上可以在 之间使用(因为 uuid 比较在PostgreSQL中已定义好):

Since you are searching for the highest bits of uuids, you can actually use between (because uuid comparison is well-defined in PostgreSQL):

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

这篇关于如何在UUID中查询postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆