在 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 就可以了!
谢谢你。