Unix Technical Forum

=?iso-8859-1?Q?R=E9f=2E_=3A__tricky_query?=

This is a discussion on =?iso-8859-1?Q?R=E9f=2E_=3A__tricky_query?= within the Pgsql Performance forums, part of the PostgreSQL category; --> I would suggest something like this, don't know how fast it is ... : SELECT (ID +1) as result ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 12:58 PM
bsimon@loxane.com
 
Posts: n/a
Default =?iso-8859-1?Q?R=E9f=2E_=3A__tricky_query?=

I would suggest something like this, don't know how fast it is ... :

SELECT (ID +1) as result FROM my_table
WHERE (ID+1) NOT IN (SELECT ID FROM my_table) as tmp
ORDER BY result asc limit 1;





"Merlin Moncure" <merlin.moncure@rcsonline.com>
Envoyé par : pgsql-performance-owner@postgresql.org
28/06/2005 16:21


Pour : <pgsql-performance@postgresql.org>
cc :
Objet : [PERFORM] tricky query


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?

Merlin

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly




---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com