【问题标题】:How to ignore dashes and spaces when searching for a phone number in a postgres database using Spring boot使用 Spring Boot 在 postgres 数据库中搜索电话号码时如何忽略破折号和空格
【发布时间】:2021-04-03 12:09:01
【问题描述】:

我对 Spring Boot 还很陌生,我需要创建一个包含一些参数(电话号码的一部分)的 get 请求,并且它应该根据该参数搜索 postgres 表并找到最佳匹配项,同时忽略该电话号码列中可能的破折号或空格。这应该怎么做?欢迎任何建议...

【问题讨论】:

标签: java spring postgresql jpa


【解决方案1】:

您应该使用函数基础索引来加快查询速度:

创建索引 test1_phone_nospace_idx ON test1 (translate(phonenum, '-', ''));

您可以查询您的数据

select * from test1 where translate(phonenum, '-', '') = '+155512123443';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 2022-09-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    相关资源
    最近更新 更多