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

Re: tricky query

From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: "John A Meinel" <john(at)arbash-meinel(dot)com>
Cc: "Postgresql Performance" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: tricky query
Date: 2005-06-28 15:39:53
Message-ID: 6EE64EF3AB31D5448D0007DD34EEB3415C2BF8@Herge.rcsinc.local (view raw or flat)
Thread:
Lists: pgsql-performance
> Not so bad. Try something like this:
> 
> SELECT min(id+1) as id_new FROM table
>     WHERE (id+1) NOT IN (SELECT id FROM table);
> 
> Now, this requires probably a sequential scan, but I'm not sure how
you
> can get around that.
> Maybe if you got trickier and did some ordering and limits. The above
> seems to give the right answer, though.

it does, but it is still faster than generate_series(), which requires
both a seqscan and a materialization of the function.
 
> I don't know how big you want to scale to.

big. :)

merlin

Responses

pgsql-performance by date

Next:From: John A MeinelDate: 2005-06-28 15:42:28
Subject: Re: tricky query
Previous:From: Merlin MoncureDate: 2005-06-28 15:30:34
Subject: Re: tricky query

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