[pgsql-jp: 25342] NULLをselectから外す時

Hiroya Torii torii @ bl.mmtr.or.jp
2002年 3月 19日 (火) 18:25:41 JST


こんにちは。NULLの挙動がちょっとわからなかったので質問します。

あるテーブルがあって、しばらく後に更新日時を追加するために
カラムを追加しました。
で、最終更新日時を得ようとしてはまりました。

まずテーブルと仮データ入力
create table test_tbl (
  index int4
);
insert into test_tbl values(1);
insert into test_tbl values(2);
insert into test_tbl values(3);
insert into test_tbl values(4);
insert into test_tbl values(5);

更新日時用カラム追加
alter table test_tbl add column regtime datetime;

仮に更新があったとする
update test_tbl set regtime='now' where index=3;

で、
tdb=# select * from test_tbl;
 index |        regtime
-------+------------------------
     1 |
     2 |
     4 |
     5 |
     3 | 2002-03-19 18:14:40+09
(5 rows)

tdb=# select * from test_tbl where regtime=NULL;
 index | regtime
-------+---------
     1 |
     2 |
     4 |
     5 |
(4 rows)

これはわかります。ですが

tdb=# select * from test_tbl where regtime<>NULL;
 index | regtime
-------+---------
(0 rows)

これがわかりません。ここではindex=3の日付が出て欲しいのに…
結局、全部にダミーの日付を入れて回避できましたが、この一連の
作業でどこが問題なのでしょうか?

使用環境は
OS : RedHatLinux7.2
DB : PostgreSQL7.1.3 


-- 
      __________
     (_ _______()
     __||_[]_||__
    (___________()
       ||‡‡||             鳥居 大哉 (Hiroya TORII)
       ||    ||           mailto:torii @ bl.mmtr.or.jp
   ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■





pgsql-jp メーリングリストの案内