如何在PostgreSQL中搜索一系列整数?

Spe*_*hal 1 postgresql search integer

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

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

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

xan*_*ont 8

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

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

select * from "table" where id::text like '19%'
Run Code Online (Sandbox Code Playgroud)

  • 我会建议`其中CAST(id AS text)就像'19%'`但``id :: text`更好. (3认同)
  • 但是,`CAST(id AS xxx)`是标准的SQL强制语法. (2认同)