トップ «前の日記(2015-07-13(Mon)) 最新 次の日記(2015-07-15(Wed))» 編集

屑俺日記

僕の備忘録(PC、UN*X、ネットワーク関連が中心)なんです。
自分の書いたところは適当(な時とか)に書き換えますので御了承を。


2015-07-14(Tue)

真偽値

MySQLとPostgresは用意されている。

mysql> select True, False;
+------+-------+
| TRUE | FALSE |
+------+-------+
|    1 |     0 |
+------+-------+
1 row in set (0.00 sec)
mydb=> select True, False;
 bool | bool 
------+------
 t    | f
(1 行)

sqliteなら、checkなどで制限することになるらしい。

sqlite> .schema bool
CREATE TABLE bool 
(num integer primary key, 
 bool integer check 
  (bool = 0 or bool = 1));
 
sqlite> insert into bool (bool) values(1);
sqlite> insert into bool (bool) values(0);
sqlite> select * from bool;
num   bool         
----  -------------
1     1            
2     0 
sqlite> insert into bool (bool) values(1.5);
Error: CHECK constraint failed: bool
 
sqlite> insert into bool (bool) values('hoge');
Error: CHECK constraint failed: bool

not null を指定すれば、1か0しか入れられなくなる。


リンクはご自由にどうぞ。でもURLや内容が変った場合はあしからず。

index.htmlは ここから。