postgresql - 获取 PostgreSQL 列中所有现有值的集合

标签 postgresql

有一个包含大约 500,000 行的表。其中一列是字符串字段。

有没有办法在 PostgreSQL 中获取该字符串的所有现有值的集合,而不必从数据库中请求每一行并手动将值添加到集合中?

例子:

first_name      last_name
will            i.am            
will            smith
britney         spears

“first_name”的所有现有值的集合将是 ['will', 'britney']

最佳答案

SELECT DISTINCT first_name FROM people;

SELECT first_name FROM people GROUP BY first_name;

关于postgresql - 获取 PostgreSQL 列中所有现有值的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13079821/

相关文章:

针对 PPGool II 的 Java 查询导致 "unnamed prepared statement does not exist"错误

Postgresql如何从一个表中选择仅在另一个表中可用的列中的值?

sql - 使用 sql 变量更新 PostgreSQL hstore 字段

postgresql - Postgres 和 Atlassian Jira : driver issue

sql - 如何为给定的一组行创建某种迭代器(或人工 ID)?

sql - 无法让 DISTINCT + GROUP 与具有两个值的 Postgres 一起使用

postgresql - 如何强制 PostgreSQL 使用我的索引?

postgresql - 微调约束触发器何时触发

database - 如何将数据库附加到 Heroku 中的应用程序?

postgresql - 整数 : "null" 的无效输入语法