X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CDDC2D1B17C for ; Wed, 2 Jun 2004 00:11:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29972-03 for ; Wed, 2 Jun 2004 03:11:04 +0000 (GMT) Received: from tht.net (vista.tht.net [216.126.88.2]) by svr1.postgresql.org (Postfix) with ESMTP id 054B5D1B196 for ; Wed, 2 Jun 2004 00:11:03 -0300 (ADT) Received: from [134.22.68.4] (dyn-68-4.tor.dsl.tht.net [134.22.68.4]) by tht.net (Postfix) with ESMTP id C8C1176A17; Tue, 1 Jun 2004 23:11:02 -0400 (EDT) Subject: Re: most efficient way to manage ordering From: Rod Taylor To: Matthew Nuzum Cc: pgsql-sql@postgresql.org In-Reply-To: <200406020235.i522Zrnb015405@ms-smtp-02.tampabay.rr.com> References: <200406020235.i522Zrnb015405@ms-smtp-02.tampabay.rr.com> Content-Type: text/plain Message-Id: <1086145854.85942.77.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Tue, 01 Jun 2004 23:10:55 -0400 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200406/8 X-Sequence-Number: 17953 > Ideally, I'd like to figure out a single SQL query that can be run > afterwards to clean up the dsply_order to make sure that each number occurs > only one time and that there are no gaps. Well... by far the easiest way to approach this is not to clean up the gaps. Removing gaps will only make things pretty, not easier or faster. This is one of the many times it is best to differentiate between what is displayed and what is used for functional purposes. CREATE TEMPORARY SEQUENCE images_display_count; SELECT nextval('images_display_count') AS display_order , * FROM images WHERE galleryid = 1 ORDER BY real_order; DROP SEQUENCE images_display_count; There are ways of replacing the sequence that may be faster, but this will address your concern. Do your updates, etc. via real_order and show the user display_order.