pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gregory Brauer <greg@wildbrain.com>
To: Joel Burton <joel@joelburton.com>
To: pgsql-sql@postgresql.org
Subject: Re: SQL over my head...
Date: Thu, 16 May 2002 14:54:21 -0700
Message-ID: <3CE42A8D.7050305@wildbrain.com> (raw)
References: <JGEPJNMCKODMDHGOBKDNGEHLCOAA.joel@joelburton.com>

Joel Burton wrote:
>>-----Original Message-----
>>From: Gregory Brauer [mailto:greg@wildbrain.com]
>>Sent: Thursday, May 16, 2002 4:39 PM
>>To: Joel Burton
>>Cc: pgsql-sql@postgresql.org
>>Subject: Re: [SQL] SQL over my head...
>>
>>>SELECT F0.id
>>>  FROM Foo as F0
>>>  JOIN Bar as B0 ON (F0.id=B0.id)
>>> WHERE NOT EXISTS (
>>>             (SELECT *
>>>                FROM Foo AS F1,
>>>                     Bar as B1
>>>               WHERE ts < CURRENT_TIME
>>>                 AND F0.attr_a=F1.attr_a
>>>                 AND F0.attr_b=F1.attr_b
>>>                 AND B0.attr_a=B1.attr_a
>>>                 AND B1.ts > B0.ts)


Excellent!  This was very close, and put me on the right track.
Here is what ended up working:


SELECT F0.id
   FROM Foo as F0
   JOIN Bar as B0 ON (F0.bar_id=B0.id)
  WHERE NOT EXISTS
              (SELECT *
                 FROM Foo AS F1,
                 JOIN Bar as B1 ON (F1.bar_id=B1.id)
                WHERE B1.ts < CURRENT_TIMESTAMP
                  AND F0.attr_a=F1.attr_a
                  AND F0.attr_b=F1.attr_b
                  AND B0.attr_a=B1.attr_a
                  AND B1.ts > B0.ts);

There was an extra "(", and it should be CURRENT_TIMESTAMP.

Thanks!

Greg




view thread (6+ messages)

Message-ID: <3CE42A8D.7050305@wildbrain.com>
Permalink:  ../3CE42A8D.7050305@wildbrain.com/
Also on:    postgresql.org/message-id/3CE42A8D.7050305@wildbrain.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: greg@wildbrain.com, joel@joelburton.com
  Subject: Re: SQL over my head...
  In-Reply-To: <3CE42A8D.7050305@wildbrain.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