从Postgres字段的多个值中选择一个 [英] Select from any of multiple values from a Postgres field

查看:77
本文介绍了从Postgres字段的多个值中选择一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下内容的表:

 字重WORDTYPE 
a 0.3常用
0.3常见的
灰色1.2颜色
尖顶2个对象

我需要立即从数据库中取出几个不同单词的权重。我可以这样做:

  SELECT * FROM word_weight WHERE WORD ='a'OR WORD ='steeple'OR WORD ='the' ; 

但是感觉很丑,并且生成查询的代码令人讨厌。我希望有一种方法可以执行类似(伪代码)的操作:

  SELECT * FROM word_weight WHERE WORD ='a ','the'; 


解决方案

您正在描述in子句的功能。 / p>

从word_weight中选择*,其中单词('a','steeple','the');


I've got a table that resembles the following:

WORD    WEIGHT   WORDTYPE
a       0.3      common
the     0.3      common
gray    1.2      colors
steeple 2        object

I need to pull the weights for several different words out of the database at once. I could do:

SELECT * FROM word_weight WHERE WORD = 'a' OR WORD = 'steeple' OR WORD='the';

but it feels ugly and the code to generate the query is obnoxious. I'm hoping that there's a way I can do something like (pseudocode):

SELECT * FROM word_weight WHERE WORD = 'a','the';

解决方案

You are describing the functionality of the in clause.

select * from word_weight where word in ('a', 'steeple', 'the');

这篇关于从Postgres字段的多个值中选择一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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