简体   繁体   English

如何从PostgreSQL获取具有特定电子邮件域的用户?

[英]How do I get users with a specific email domain from PostgreSQL?

I want to get all users with a specific domain in their email. 我希望在其电子邮件中为所有用户提供特定域名。 How can I accomplish this with a PostgreSQL command so I don't need to fetch all the users and then filter them out with Ruby? 如何使用PostgreSQL命令完成此操作,这样我就不需要获取所有用户,然后使用Ruby过滤掉它们?

where('user.email == ?', '*@domain.com')

What's the most efficient way to do this? 最有效的方法是什么? split and then join ? split然后join Or is there a super command in PostgreSQL that you can use? 或者你可以使用PostgreSQL中的超级命令吗?

You're looking for the " like " command. 你正在寻找like ”的命令。

In particular you want something similar to: 特别是你想要类似的东西:

'user.email like "%?"'

The % is a wildcard in like clauses, that tells PostgreSQL to find the string given at the end of the field being searched. %like子句中的通配符,它​​告诉PostgreSQL查找在被搜索字段末尾给出的字符串。

PostgreSQL supports regular expressions also, but like should be sufficient for what you're after. PostgreSQL支持正则表达式也有,但是like应该够你用的是什么了。

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

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