dbTalk Databases Forums  

the phantom record

comp.databases.postgresql comp.databases.postgresql


Discuss the phantom record in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default the phantom record - 05-12-2008 , 08:35 AM






Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
Quote:
70 | 121
70 | 111
60 | 120
70 | 117
70 | 107
50 | 110
175 | 112
175 | 114
125 | 112
80 | 101
50 | 105
60 | 124
185 | 101
175 | 108
70 | 115
70 | 119
175 | 104
170 | 102
50 | 106
70 | 109
70 | 120
20 | 101
40 | 103
115 | 101
50 | 111
60 | 122
50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
Quote:
70 | 121
70 | 111
60 | 120
70 | 117
70 | 107
50 | 110
175 | 112
175 | 114
125 | 112
80 | 101
50 | 105
60 | 124
185 | 101
175 | 108
70 | 115
70 | 119
175 | 104
170 | 102
50 | 106
70 | 109
200 | 49
70 | 120
20 | 101
40 | 103
115 | 101
50 | 111
60 | 122
50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
Quote:
20 | 101
40 | 103
50 | 105
50 | 106
50 | 107
50 | 110
50 | 111
60 | 120
60 | 122
60 | 124
70 | 107
70 | 109
70 | 111
70 | 115
70 | 117
70 | 119
70 | 120
70 | 121
80 | 101
115 | 101
125 | 112
170 | 102
175 | 104
175 | 108
175 | 112
175 | 114
185 | 101
200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
Quote:
70 | 121
70 | 111
60 | 120
70 | 117
70 | 107
50 | 110
175 | 112
175 | 114
125 | 112
80 | 101
50 | 105
60 | 124
185 | 101
175 | 108
70 | 115
70 | 119
175 | 104
170 | 102
50 | 106
70 | 109
200 | 49
70 | 120
20 | 101
40 | 103
115 | 101
50 | 111
60 | 122
50 | 107
(28 rows)

myPGdb=#


Reply With Quote
  #2  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM






Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #3  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #4  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #5  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #6  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #7  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #8  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
  #9  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: the phantom record - 05-12-2008 , 09:04 AM



Nevermind, I found the reason is a duplicate value in the triplet (td,
vp, vc) on tableB. Sorry for rush out.

Coniglio Sgabbiato ha scritto:
Quote:
Hi, I have two real tables in a database, I am comparing some values and
can notice that queries that are supposed to return the same values
differs for one record. When I use the /not in/ clause I lose one record
and get 27 instead of 28 records. So let's see the queries, the data and
queries I put here are real, I changed only the name of tables and
database for privacy purposes:

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB);
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(27 rows)

myPGdb=# select td, vp, vc from tmp.tableA where (td, vp, vc) not in
(select td, vp, vc from tableB) or td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=# select td, vp, vc from tmp.tableA except select td, vp, vc from
tableB;
td | vp | vc
----+-----+-----
| 20 | 101
| 40 | 103
| 50 | 105
| 50 | 106
| 50 | 107
| 50 | 110
| 50 | 111
| 60 | 120
| 60 | 122
| 60 | 124
| 70 | 107
| 70 | 109
| 70 | 111
| 70 | 115
| 70 | 117
| 70 | 119
| 70 | 120
| 70 | 121
| 80 | 101
| 115 | 101
| 125 | 112
| 170 | 102
| 175 | 104
| 175 | 108
| 175 | 112
| 175 | 114
| 185 | 101
| 200 | 49
(28 rows)

myPGdb=# select td, vp, vc from tableB where td is null;
td | vp | vc
----+----+----
(0 rows)

myPGdb=# select td, vp, vc from tmp.tableA where td is null;
td | vp | vc
----+-----+-----
| 70 | 121
| 70 | 111
| 60 | 120
| 70 | 117
| 70 | 107
| 50 | 110
| 175 | 112
| 175 | 114
| 125 | 112
| 80 | 101
| 50 | 105
| 60 | 124
| 185 | 101
| 175 | 108
| 70 | 115
| 70 | 119
| 175 | 104
| 170 | 102
| 50 | 106
| 70 | 109
| 200 | 49
| 70 | 120
| 20 | 101
| 40 | 103
| 115 | 101
| 50 | 111
| 60 | 122
| 50 | 107
(28 rows)

myPGdb=#

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.