【发布时间】:2009-10-09 11:00:38
【问题描述】:
在 Postgresql 8 中为什么这样可以
select * from prod where code like '1%'
select * from prod where code like '%1'
但这会返回 0 行(有以数字 1 开头/结尾的代码)
select * from prod where code like '1%1'
更新
这发生在我当前的安装中:
# psql --version
psql (PostgreSQL) 8.3.7
create table a(code char(10));
CREATE TABLE
db=# insert into a values('111');
INSERT 0 1
db=# select * from a where code like '1%';
code
------------
111
(1 row)
db=# select * from a where code like '%1';
code
------
(0 rows)
db=# select * from a where code like '1%1';
code
------
(0 rows)
更新 2
这是数据类型!使用 varchar 就可以了!
谢谢。
【问题讨论】:
-
您可能想编辑您的问题 - 我不明白。如果 postgres 没有在您的查询中显示代码为“111”(例如)的数据,那么有些东西坏了,但老实说 - 我真的不相信。向我们展示数据、查询、收到的结果和预期的结果。
标签: postgresql sql-like