Re: Query, view join question. - Mailing list pgsql-general

From Joost Kraaijeveld
Subject Re: Query, view join question.
Date
Msg-id A3D1526C98B7C1409A687E0943EAC41001EB26@obelix.askesis.nl
Whole thread Raw
Responses Re: Query, view join question.  (vhikida@inreach.com)
Re: Query, view join question.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi Tom,

pgsql-general-owner@postgresql.org schreef:
> "Joost Kraaijeveld" <J.Kraaijeveld@Askesis.nl> writes:
>> CREATE OR REPLACE VIEW even AS
>>  SELECT DISTINCT abo_his.klantnummer,
> abo_his.artikelnummer, abo_his.code_retour,
> abo_klt.aantal_abonnementen, abo_klt.afgewerkt
>>    FROM abo_his
>>    JOIN abo_klt ON abo_his.klantnummer = abo_klt.klantnummer
>>   WHERE abo_his.abonnement = 238
>>   ORDER BY abo_his.klantnummer, abo_his.artikelnummer,
> abo_his.code_retour, abo_klt.aantal_abonnementen, abo_klt.afgewerkt;
>
> Okay ... but the view is constraining abo_his.abonnement and
> outputting abo_klt.aantal_abonnementen.  Why would you assume that
> joining on klantnummer would cause these two fields to necessarily be
> the same?

In the table abo_klt there is no record where abo_klt.abonnement = 238 and abo_klt.afgewerkt > 0:

munt=# select * from abo_klt where abonnement = 238 and afgewerkt > 0;
...
(0 rows)

So I assumed that in no join between abo_his (which has no "afgewerkt" column at all ) and abo_klt (which has 0 records
witha "afgewerkt" columns > 0) as created above ( with WHERE abo_his.abonnement = 238) there could be a record with
bothabonnement = 238 and afgewerk >0. 

But there are:

on the view there are :
munt=# select * from even where  afgewerkt > 0;
.....
(797 rows)

SO I must understand something wrong...

Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J.Kraaijeveld@Askesis.nl
web: www.askesis.nl

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dump dependencies
Next
From: "Net Virtual Mailing Lists"
Date:
Subject: ltree valid characters