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

Re: tricky query

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: tricky query
Date: 2005-06-28 15:42:42
Message-ID: 20050628154242.GS62747@colo.samason.me.uk (view raw or flat)
Thread:
Lists: pgsql-performance
Merlin Moncure wrote:
>I've already worked out a query using generate_series (not scalable) and
>pl/pgsql.  An SQL only solution would be preferred, am I missing
>something obvious?

I would be tempted to join the table to itself like:

  SELECT id+1
  FROM foo
  WHERE id > 0
    AND i NOT IN (SELECT id-1 FROM foo)
  LIMIT 1;

Seems to work for me.  Not sure if that's good enough for you, but
it may help.

  Sam

In response to

pgsql-performance by date

Next:From: John A MeinelDate: 2005-06-28 15:43:25
Subject: Re: tricky query
Previous:From: Karl O. PincDate: 2005-06-28 15:42:32
Subject: Fwd: Re: [PERFORM] Performance analysis of plpgsql code [kop@meme.com]

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