Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6FA9AB5DBE8 for ; Tue, 5 Jul 2011 18:42:38 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 79672-07 for ; Tue, 5 Jul 2011 21:42:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from newserver.jfcomputer.com (unknown [76.14.161.106]) by mail.postgresql.org (Postfix) with ESMTP id 48E41B5DBF6 for ; Tue, 5 Jul 2011 18:42:32 -0300 (ADT) Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 5138B12294 for ; Tue, 5 Jul 2011 21:42:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ERyERm2L54eD for ; Tue, 5 Jul 2011 14:42:30 -0700 (PDT) Received: from linux-desktop.localnet (unknown [192.168.1.111]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@jfcomputer.com) by newserver.jfcomputer.com (Postfix) with ESMTPSA id 611BB4E04 for ; Tue, 5 Jul 2011 14:42:30 -0700 (PDT) From: John Fabiani Organization: J.F. Computer Solutions To: pgsql-sql@postgresql.org Subject: Re: interesting sequence Date: Tue, 5 Jul 2011 14:42:29 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34.8-0.2-desktop; KDE/4.4.4; i686; ; ) References: <201107050652.22187.johnf@jfcomputer.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201107051442.29875.johnf@jfcomputer.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.106 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793, TO_NO_BRKTS_NORDNS=0.001 X-Spam-Level: X-Archive-Number: 201107/14 X-Sequence-Number: 35584 On Tuesday, July 05, 2011 01:11:11 pm Kevin Crain wrote: > You don't need a loop there. Assuming your order id field is of type > varchar you can just build the first part of your string and then do a > count to get the last part using a LIKE comparison: > > select count(id_order) + 1 from sometable WHERE id_order LIKE 'O-20110704 > -%'; > > If you do this inside a function it will be like running it in a > transaction so you shouldn't have to worry about it being a multi-user > system. > > > I like this - looks better than what I'm currently doing. Thanks Johnf