Re: SELECT Question - Mailing list pgsql-general

From Kris Jurka
Subject Re: SELECT Question
Date
Msg-id Pine.LNX.4.33.0311200448190.23198-100000@leary.csoft.net
Whole thread Raw
In response to Re: SELECT Question  (Alex <alex@meerkatsoft.com>)
Responses Re: SELECT Question  (Joe Conway <mail@joeconway.com>)
List pgsql-general

On Thu, 20 Nov 2003, Alex wrote:
> >>Is there an easy way to write a select statement that returns me the
> >>frist free number or any within the range of 200?
> >>For example if 1-30, and 32-50 are occupied then i would like to fill in
> >>the new entry with id 31.

If you had a table with an id column and 200 rows 1-200 you could do

SELECT MIN(idtab.id) FROM idtab LEFT JOIN realtab ON (idtab.id =
realtab.id AND realtab.id IS NULL)

A useful generic function would be one something like range(min,max) that
would return a set of rows so you wouldn't have to actually have a table.

Kris Jurka


pgsql-general by date:

Previous
From: "Matthew Lunnon"
Date:
Subject: Re: Pg_dumpall problem
Next
From: Jean-Michel POURE
Date:
Subject: Re: Japanese and PostgreSQL