[pgsql-jp: 26173] left outer joinした後のNULLを検索できません。
Yoshitake Shinohara
yoshi @ yyn.jp
2002年 5月 29日 (水) 02:18:07 JST
みなさま、はじめまして。
よしたけ@YYNと申します。
7.1.2から7.2.1へ本日(って、もう昨日ですね(T.T))バージョンアップを行いま
して、今まで動いていたコードが動かなくなってしまいました。
drop table tmp;
create table tmp(
id int4,
mail text,
name text,
note text
);
drop table address;
create table address(
id int4,
mail text,
name text,
flag int4
);
insert into tmp values (1,'123 @ foo.bar','123','qaz');
insert into tmp values (1,'456 @ foo.bar','456','wsx');
insert into tmp values (2,'789 @ foo.bar','789','edc');
insert into address values (1,'456 @ foo.bar','456',1);
というテーブル/データがあるとします。
「addressにid,mailの組み合わせで登録されていないtmpのデータをaddressに
登録したい。」
という事を行いたいと思っております。
これに対し、7.1.2では
insert into address (id,mail,name,flag) (
select t.id,t.mail,t.name,1 from tmp t
left outer join address a
on t.id = a.id and t.mail = a.mail
where a.mail <> t.mail or a.mail = NULL
);
という内容のコードで実現しておりました。(実際にはテーブル名等多少違い
ます)
このコードで7.2.1にて実行すると、
INSERT 0 0
という結果で登録できません。
調べてみたところ、
test=# select * from tmp t
test-# left outer join address a
test-# on t.id = a.id and t.mail = a.mail
test-# ;
id | mail | name | note | id | mail | name | flag
----+-------------+------+------+----+-------------+------+------
1 | 123 @ foo.bar | 123 | qaz | | | |
1 | 456 @ foo.bar | 456 | wsx | 1 | 456 @ foo.bar | 456 | 1
2 | 789 @ foo.bar | 789 | edc | | | |
(3 rows)
とwhere句を定義しなければ期待通りに表示されるのですが、
test=# select * from tmp t
test-# left outer join address a
test-# on t.id = a.id and t.mail = a.mail
test-# where a.mail <> t.mail or a.mail = NULL
test-# ;
id | mail | name | note | id | mail | name | flag
----+------+------+------+----+------+------+------
(0 rows)
と本来表示されてほしい123 @ foo.barと789 @ foo.barのレコードが表示されません。
7.2.1にて仕様変更になった箇所なのか、バグなのか、それともコーディングの
ミスなのか教えていただけますよう、お願いいたします。
また、こちらの対処方法もございましたらばお教え頂ければ幸いです。
------------------------
YYN partnership company
Yoshitake Shinohara
yoshi @ yyn.jp
pgsql-jp メーリングリストの案内