Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7oR6-0000Lt-5t for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 15:49:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W7oR5-00027e-KO for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 15:49:19 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7oR3-00025m-QP for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 15:49:17 +0000 Received: from adsltrust.ath.forthnet.gr ([194.219.204.174] helo=smadev.internal.net) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7oQz-0004Cm-8O for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 15:49:17 +0000 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.14.7/8.14.7) with ESMTP id s0RFnAFb038678 for ; Mon, 27 Jan 2014 17:49:10 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Message-ID: <52E67FF6.9060806@matrix.gatewaynet.com> Date: Mon, 27 Jan 2014 17:49:10 +0200 From: Achilleas Mantzios User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Update ordered References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) 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 27/01/2014 16:36, 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. I think that makes sense. When you UPDATE ... FROM an another relation, nothing is guaranteed about the order of the from_list join. Therefore "order by created asc" in your CTE is not gonna achieve much. Your better write this as a procedure. (as you have already suggested) > Any idea how to achive this? > 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 -- Achilleas Mantzios Head of IT DEV IT DEPT Dynacom Tankers Mgmt -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql