介绍:
布尔类型的 *** 作符:逻辑 *** 作符和比较 *** 作符
逻辑 *** 作符:and,or,not
需要注意的是:false and null结果为false
比较运算符:is
is true
is false
is not true
is not false
is unkNown
is not unkNown
is null
is not null
登陆测试数据库创建测试测试表插入数据来演示:
1.登陆库testdb1:
[postgres@localhost ~]$ psql -Utestwjw -h 127.0.0.1 -d testdb1 -p 36985
Password for user testwjw: 输入密码:558996
psql.bin (9.5.9)
Type "help" for help.
2.创建表:
boolean的状态要么是true要么是false,如果是unkNown,用NulL表示。
boolean在sql中可以用不带引号的TRUE和FALSE表示,也可以用更多的表示真假的带引号的字符表示,如'true','false','yes','no','1','0'等
testdb1=> create table t (ID int,nan boolean,note text);
CREATE table
3.查看库中所有的表:
testdb1=> \dt
List of relations
Schema | name | Type | Owner
--------+-------+-------+---------
public | t | table | testwjw
public | tlb01 | table | testwjw
testdb1=>
4.t表中插入数据:
testdb1=> insert into t values(1,TRUE,'TRUE');
INSERT 0 1
testdb1=> insert into t values(2,FALSE,'FALSE');
INSERT 0 1
testdb1=> insert into t values(3,tRue,'tRue')
testdb1-> ;
INSERT 0 1
testdb1=> insert into t values(4,fAlse,'fAlse');
INSERT 0 1
给t表中插入空数值NulL:
testdb1=> insert into t values(11,null,'null');
INSERT 0 1
testdb1=> insert into t values(11,NulL,'NulL');
INSERT 0 1
5.查看表中的数值:
testdb1=> select * from t;
ID | nan | note
----+-----+-------
1 | t | TRUE
2 | f | FALSE
3 | t | tRue
4 | f | fAlse
11 | | null
11 | | NulL
(6 rows)
select * from t where nan='t';
ID | nan | note
----+-----+------
1 | t | TRUE
3 | t | tRue
(2 rows)
testdb1=> select * from t where nan; 特殊的查询方式:
ID | nan | note
----+-----+------
1 | t | TRUE
3 | t | tRue
(2 rows)
testdb1=>
testdb1=> select * from t where nan<>'t';
ID | nan | note
----+-----+-------
2 | f | FALSE
4 | f | fAlse
(2 rows)
testdb1=>
testdb1=> select * from t where not nan;
ID | nan | note
----+-----+-------
2 | f | FALSE
4 | f | fAlse
(2 rows)
testdb1=>
testdb1=> select * from t where nan or not nan;
ID | nan | note
----+-----+-------
1 | t | TRUE
2 | f | FALSE
3 | t | tRue
4 | f | fAlse
(4 rows)
testdb1=> select * from t where nan and not nan;
ID | nan | note
----+-----+------
(0 rows)
testdb1=> select * from t where nan is null;
ID | nan | note
----+-----+------
11 | | null
11 | | NulL
(2 rows)
testdb1=> select * from t where nan is unkNown; ####神奇
ID | nan | note
----+-----+------
11 | | null
11 | | NulL
(2 rows)
testdb1=>
testdb1=> select * from t where nan is not null;
ID | nan | note
----+-----+-------
1 | t | TRUE
2 | f | FALSE
3 | t | tRue
4 | f | fAlse
(4 rows)
testdb1=>
插入数值:
testdb1=> insert into t values(7,'t','''t''');
INSERT 0 1
testdb1=> insert into t values(8,'f','''f''');
INSERT 0 1
testdb1=> insert into t values(9,'''yes''');
INSERT 0 1
testdb1=> insert into t values(10,'0','''0''');
INSERT 0 1
testdb1=> select * from t;
ID | nan | note
----+-----+-------
1 | t | TRUE
2 | f | FALSE
3 | t | tRue
4 | f | fAlse
11 | | null
11 | | NulL
7 | t | 't'
8 | f | 'f'
9 | t | 'yes'
10 | f | '0'
(10 rows)
testdb1=> select * from t where nan is not true ;
ID | nan | note
----+-----+-------
2 | f | FALSE
4 | f | fAlse
11 | | null
11 | | NulL
8 | f | 'f'
10 | f | '0'
(6 rows)
testdb1=> select * from t where nan is true ;
ID | nan | note
----+-----+-------
1 | t | TRUE
3 | t | tRue
7 | t | 't'
9 | t | 'yes'
(4 rows)
testdb1=> select * from t where nan is not false ;
ID | nan | note
----+-----+-------
1 | t | TRUE
3 | t | tRue
11 | | null
11 | | NulL
7 | t | 't'
9 | t | 'yes'
(6 rows)
总结以上是内存溢出为你收集整理的PostgreSQL9.5.9学习篇布尔类型 *** 作符select查询全部内容,希望文章能够帮你解决PostgreSQL9.5.9学习篇布尔类型 *** 作符select查询所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)