WITH foo AS
(
SELECT column1::integer id, column2::timestamp ts
FROM (VALUES
(0, '1-Jan-2010 20:00'),
(1, '1-Jan-2010 20:03'),
(1, '1-Jan-2010 20:04'),
(0, '1-Jan-2010 20:05'),
(1, '1-Jan-2010 20:05'),
(0, '1-Jan-2010 20:08'),
(1, '1-Jan-2010 20:09'),
(0, '1-Jan-
On Sat, Jun 4, 2011 at 6:36 PM, wrote:
> 0 20:00
> 0 20:05
> 0 20:08
> 0 20:10
>
> I want records, starting from the oldest record (20:00), that are at least 5
> minutes apart. So 20:00, 20:05, 20:10 but 20:08 - 20:05 is only 3 minutes so
> it is to be ignored.
Here is
Let's a take a look at just the input set for ID 0.
0 20:00
0 20:05
0 20:08
0 20:10
I want records, starting from the oldest record (20:00), that are at least 5
minutes apart. So 20:00, 20:05, 20:10 but 20:08 - 20:05 is only 3 minutes so
it is to be ignored.
I was hoping
My approach would be to add a column for LAST_TS and place a trigger
on insert that populates this new column. Then you have something you
can put in your WHERE clause to test on.
On Fri, Jun 3, 2011 at 12:52 PM, wrote:
> I have a table that, at a minimum, has ID and timestamp columns. Records
Why is (0,20:10) listed in your expected results when there is a (0,20:08)?
On Fri, Jun 3, 2011 at 12:52 PM, wrote:
> I have a table that, at a minimum, has ID and timestamp columns. Records
> are inserted into with random IDs and timestamps. Duplicate IDs are allowed.
>
> I want to select re
Did you mean WHERE in place of your first AND? If so I already had something
like this but it only returns one set, the oldest group of entries for each
ID.
On Sat, Jun 04, 2011 at 01:09:39PM -0700, Richard Broersma wrote:
> On Sat, Jun 4, 2011 at 12:15 PM, wrote:
> > I want to
> > select rec
SELECT a.*
FROM foo a
INNER JOIN foo b
ON b.id = a.id
AND b.ts >= a.ts + '5 minutes'
GROUP BY a.id, a.ts
ORDER BY a.id, a.ts
Not clear yet on the needs, but this may give a start.
- Reply message -
From: lists-pg...@useunix.net
Date: Sat, Jun 4, 2011 4:15 pm
Subject: [SQL] selecti
On Sat, Jun 4, 2011 at 12:15 PM, wrote:
> I want to
> select records grouped by ID, ordered by timestamp, in ascending order so I'm
> starting with the oldest, that are at least X minutes apart.
Here my guess:
SELECT id, ts
FROM Yourtable AS A
AND NOT EXISTS ( SELECT *
On Sat, Jun 04, 2011 at 11:45:08AM +, Jasen Betts wrote:
> On 2011-06-03, lists-pg...@useunix.net wrote:
> >
> > ID TS (HH:MM)
> > ---
> > 0 20:00
> > 0 20:05
> > 0 20:10
> > 1 20:03
> > 1 20:09
> >
> >
> > Does my question make sense?
>
> no, why is (1,20:04) exclu
The TS column type is actually a timestamp with out timezone and yes I want to
take seconds into account so both of your entries would be included in the
result.
On Fri, Jun 03, 2011 at 06:01:53PM -0700, Kevin Crain wrote:
> Will you be using a full timestamp with that or are you only concerned
>
It looks like maybe he is trying to fetch records that either have no
previous entries or have another record with a timestamp 5 minutes
before them at the time they are inserted...
On Sat, Jun 4, 2011 at 4:45 AM, Jasen Betts wrote:
> On 2011-06-03, lists-pg...@useunix.net wrote:
>>
>> ID TS
On 2011-06-03, lists-pg...@useunix.net wrote:
>
> IDTS (HH:MM)
> ---
> 0 20:00
> 0 20:05
> 0 20:10
> 1 20:03
> 1 20:09
>
>
> Does my question make sense?
no, why is (1,20:04) excluded, but (0,20:05) included?
both records are 5 minutes from the newest.
--
12 matches
Mail list logo