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

tricky query

From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: <pgsql-performance(at)postgresql(dot)org>
Subject: tricky query
Date: 2005-06-28 14:21:16
Message-ID: 6EE64EF3AB31D5448D0007DD34EEB3415C2BEC@Herge.rcsinc.local (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
I need a fast way (sql only preferred) to solve the following problem:

I need the smallest integer that is greater than zero that is not in the
column of a table.  In other words, if an 'id' column has values
1,2,3,4,6 and 7, I need a query that returns the value of 5.

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?



pgsql-performance by date

Next:From: Tom LaneDate: 2005-06-28 14:25:59
Subject: Re: Insert performance vs Table size
Previous:From: Erik WestlandDate: 2005-06-28 14:18:05

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