Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7o2v-0007oH-Uq for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 15:24:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W7o2v-0000jY-De for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 15:24:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7o2u-0000iX-9K for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 15:24:20 +0000 Received: from mail-pb0-x22e.google.com ([2607:f8b0:400e:c01::22e]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7o2q-0005qi-En for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 15:24:19 +0000 Received: by mail-pb0-f46.google.com with SMTP id um1so5971038pbc.19 for ; Mon, 27 Jan 2014 07:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=3i+u91BdnFAR5t7tDK4B/vEazuifPbdIWCAGfqsbZJA=; b=YGgb7wTiUoqzASvYyz00fA5NgJxpt46egHtbj0UvEMEi1cyBSAWkm1CJqRWWHr0OWM E5EwKnrYscpk4bjaX7Ibj0GBFuOWG6oXZROQRKIM6X7UAJKkNJ5xk0dVebgApew9rxdi xvjld6za3rb2PxK28NQv3c3j6VEz+C2z+AZbbCcDaDqiwc61jDRsMkIXzAcXu00T773f r5NZZfl7tmIRBUwCSqUb1JDdIALVQwEwdrp4/cFU1mFErH/gYAxqyi8kGFttc/3MLEk2 MTdQdqLbFWFZvleYZ30As8IOvl8ZVqcNL8Yj9GQgjvcByz+Q8qJIJ5GDW5wvvKOVs2L2 5BUg== X-Received: by 10.66.123.5 with SMTP id lw5mr30928800pab.83.1390836254339; Mon, 27 Jan 2014 07:24:14 -0800 (PST) Received: from panda.site (65-102-185-39.tukw.qwest.net. [65.102.185.39]) by mx.google.com with ESMTPSA id j3sm32781391pbh.38.2014.01.27.07.24.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 27 Jan 2014 07:24:11 -0800 (PST) Message-ID: <52E67A0C.5020605@gmail.com> Date: Mon, 27 Jan 2014 07:23:56 -0800 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Andreas Joseph Krogh , pgsql-sql@postgresql.org Subject: Re: Update ordered References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 01/27/2014 07:01 AM, Andreas Joseph Krogh wrote: > På mandag 27. januar 2014 kl. 15:56:12, skrev Adrian Klaver > >: > > On 01/27/2014 06:36 AM, Andreas Joseph Krogh wrote: > > Hi all. > > I want an UPDATE query to update my project's project_number in > > chronological order (according to the project's "created"-column) and > > tried this: > > with upd as( > > select id from project order by created asc > > ) update project p set project_number = get_next_project_number() > from > > upd where upd.id = p.id; > > However, the olders project doesn't get the smalles project_number. > > Any idea how to achive this? > > That would seem to depend on what get_next_project_number() does, the > contents of which are unknown. > > get_next_project_number() gets the next project-number based on some > custom logic. > What would be the best way to update all project's project-number having > the oldes project get the first number returned by > get_next_project_number() etc.? How are you sure it is not, have you tried something like below to test?: with upd as( select id from project order by created asc ) select p.id, p.create from project_number where upd.id = p.id; > Thanks. > -- > Andreas Joseph Krogh mob: +47 909 56 963 > Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no > Public key: http://home.officenet.no/~andreak/public_key.asc -- Adrian Klaver adrian.klaver@gmail.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql