如何在PostgreSQL中搜索一系列整数? [英] How do I search for a range of integers in PostgreSQL?

查看:137
本文介绍了如何在PostgreSQL中搜索一系列整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个整数列,我需要搜索上述列以19开头的行

I have an integer column and I need to search for rows in which the said column starts with 19

在MySQL中我会使用SELECT ... WHERE id LIKE '19%'

In MySQL I would use SELECT ... WHERE id LIKE '19%'

ERROR:  operator does not exist: integer ~~ unknown
LINE 1: select * from "table" where "id" like '19%'


推荐答案

在Postgres中LIKE是字符串比较 - 这解释了错误。

In Postgres LIKE is string compare only - that explains the error.

您可以显式地将列转换为字符串:

You can explicitly cast the column to string though:

select * from "table" where id::text like '19%'

这篇关于如何在PostgreSQL中搜索一系列整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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