Skip site navigation (1) Skip section navigation (2)

Re: Finding missing values in sequence column

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Finding missing values in sequence column
Date: 2010-12-30 18:49:49
Message-ID: ifik8d$mo8$1@reversiblemaps.ath.cx (view raw or flat)
Thread:
Lists: pgsql-admin
On 2010-12-30, Lukasz Brodziak <lukasz(dot)brodziak(at)gmail(dot)com> wrote:
> Hello,
>
> I have a problem with writing a select statement that would return
> records for which difference in values of this and following ID is
> bigger than 1. Example table
> ID      Data
> 1       Text
> 2       Text2
> 5       Text5
> 23     Text23
> 24     TXT
> 25     RRRR
>
> So I need to return rows with IDs 2,5,23.

SELECT id FROM Example EXCEPT SELECT id-1 FROM Example;

select * FROM Example WHERE id+1 NOT IN ( SELECT id FROM Example );





> -- 
> Łukasz Brodziak
> "What if everyting around You isn't quite as it seems,
> What if all the world You think You know is an inelaborate dream
> When You look at Your reflection is that all you want it to be
> What if You could look right through the cracks
> Would You find Yourself...... Find Yourself afraid to see"
>


-- 
⚂⚃ 100% natural

In response to

pgsql-admin by date

Next:From: Dan ColemanDate: 2010-12-30 23:37:27
Subject: syntax error at or near ";" at character 41
Previous:From: Scott RibeDate: 2010-12-30 15:10:49
Subject: Re: pg v. 8.4.5 misses objects and data after restoring from backup using wal

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group