如何将整数转换为字符串作为PostgreSQL查询的一部分?

例如,我需要:

SELECT * FROM table WHERE <some integer> = 'string of numbers'

其中<some integer>可以是1到15位数的任意长度.

推荐答案

因为数字最多可以是15位,所以需要转换为64位(8字节)整数.试试这个:

SELECT * FROM table
WHERE myint = mytext::int8

::名演员的运营商历史悠久,但很方便.Postgres也符合SQL标准语法

myint = cast ( mytext as int8)

如果要将文本与int进行比较,请将int转换为文本:

SELECT * FROM table
WHERE myint::varchar(255) = mytext

Postgresql相关问答推荐

将列类型从文本[]更改为jsonb[]

使用postgres在go测试容器中使用tern迁移

使用Helm设置PostgreSQL配置

gorm 创建并返回值 many2many

将 postgres 从属提升为主 node

PostgreSQL:please specify covering index name是什么意思

如何从 postgresql Select 查询中的 age() 函数中仅获取年份

升级到 OSX Mavericks 后修复 postgresql

PostgreSQL 可以对数组元素有唯一性约束吗?

无法识别的配置参数bytea_output

错误:CASE types character varying and numeric cannot be matched

无法使用 sequelize 从本地 node 应用程序连接到 heroku postgresql 数据库

从time without time zone和时区名称中获取time with time zone

Rails 验证数组中的值

python pip install psycopg2 安装错误

PostgreSQL 嵌套 CTE 和 UNION

PostgreSQL 中的行编号

如果 PostgreSQL count(*) 总是很慢,如何对复杂查询进行分页?

python postgres 我可以 fetchall() 100 万行吗?

如何在postgres中将整数分钟转换为间隔