pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Loredana Curugiu <loredana.curugiu@gmail.com>
Cc: pgsql-novice@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: JOIN
Date: Tue, 05 Jun 2007 14:21:44 +0100
Message-ID: <46656368.7080504@archonet.com> (raw)
In-Reply-To: <1c23c8e70706050559n60615ba7kab11f6f0f402d9ec@mail.gmail.com>
References: <1c23c8e70706050111i5ba672d6j78bd9afa4b786616@mail.gmail.com>
	<1c23c8e70706050426y12d567ban70ffdafb75808e0e@mail.gmail.com>
	<4665537A.2060601@archonet.com>
	<1c23c8e70706050518v19c56d21j873985125b930db@mail.gmail.com>
	<46655981.4050403@archonet.com>
	<1c23c8e70706050559n60615ba7kab11f6f0f402d9ec@mail.gmail.com>

Loredana Curugiu wrote:
>>> You don't actually say what's wrong. What are you expecting as output?
> 
> I should obtain the following result:
[snip]

Well, I've attached a test script using your example data and a copy of 
my results. Nothing leaping out as wrong here. It's entirely possible 
I've not had enough coffee today though and I'm missing something 
staring me in the face...

-- 
   Richard Huxton
   Archonet Ltd

Attachments:

test_results.txt (text/plain, 6.7K) download sum | theme | receiver | date | dates -----+-------+--------------+------------------------+-------------------------------------------------------------------------------- 3 | CRIS | +40741775622 | 2007-06-01 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 2 | CRIS | +40741775622 | 2007-06-02 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 3 | CRIS | +40741775622 | 2007-06-03 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 18 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 4 | LIA | +40741775621 | 2007-06-01 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 4 | LIA | +40741775621 | 2007-06-02 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 6 | LIA | +40741775621 | 2007-06-03 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 10 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} (8 rows) count | theme | receiver | date | dates -------+-------+--------------+------------------------+-------------------------------------------------------------------------------- 3 | CRIS | +40741775622 | 2007-06-01 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | CRIS | +40741775622 | 2007-06-02 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | CRIS | +40741775622 | 2007-06-02 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | CRIS | +40741775622 | 2007-06-03 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | CRIS | +40741775622 | 2007-06-03 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | CRIS | +40741775622 | 2007-06-03 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | CRIS | +40741775622 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 4 | LIA | +40741775621 | 2007-06-01 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 2 | LIA | +40741775621 | 2007-06-02 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 2 | LIA | +40741775621 | 2007-06-02 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 2 | LIA | +40741775621 | 2007-06-03 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 2 | LIA | +40741775621 | 2007-06-03 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 2 | LIA | +40741775621 | 2007-06-03 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1 | LIA | +40741775621 | 2007-06-04 00:00:00+00 | {2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} (40 rows)
zzz_test.sql (text/x-sql, 2.1K) download /* CREATE TABLE loredana_test ( count int4, theme text, receiver text, "date" timestamptz, dates date[] ); COPY loredana_test FROM stdin WITH DELIMITER '|'; 2|LIA|+40741775621|2007-06-02 00:00:00+00|{2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1|LIA|+40741775621|2007-06-04 00:00:00+00|{2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 3|CRIS|+40741775622|2007-06-01 00:00:00+00|{2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07} 1|CRIS|+40741775622|2007-06-04 00:00:00+00|{2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 2|LIA|+40741775621|2007-06-03 00:00:00+00|{2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} 1|CRIS|+40741775622|2007-06-04 00:00:00+00|{2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 1|CRIS|+40741775622|2007-06-03 00:00:00+00|{2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1|CRIS|+40741775622|2007-06-04 00:00:00+00|{2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09,2007-06-10} 4|LIA|+40741775621|2007-06-01 00:00:00+00|{2007-06-01,2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06} 1|LIA|+40741775621|2007-06-04 00:00:00+00|{2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08,2007-06-09} 1|CRIS|+40741775622|2007-06-02 00:00:00+00|{2007-06-02,2007-06-03,2007-06-04,2007-06-05,2007-06-06,2007-06-07,2007-06-08} \. */ -- Uncomment one of these to control whether any rows match SET timezone = 'GMT'; -- SET timezone = 'GB'; -- Original query, but with the "date" column displayed too SELECT SUM(A.count), A.theme, A.receiver, A.date, A.dates FROM loredana_test A INNER JOIN loredana_test B ON A.theme=B.theme AND A.receiver=B.receiver AND A.date = ANY(B.dates) GROUP BY A.theme,A.receiver,A.date,A.dates; -- Query to test matches SELECT A.count, A.theme, A.receiver, A.date, B.dates FROM loredana_test A INNER JOIN loredana_test B ON A.theme=B.theme AND A.receiver=B.receiver AND A.date = ANY(B.dates) ORDER BY A.theme, A.receiver, A.date ;

view thread (22+ messages)  latest in thread

Message-ID: <46656368.7080504@archonet.com>
Permalink:  ../46656368.7080504@archonet.com/
Also on:    postgresql.org/message-id/46656368.7080504@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, loredana.curugiu@gmail.com, pgsql-novice@postgresql.org
  Subject: Re: JOIN
  In-Reply-To: <46656368.7080504@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox