Re: Update ordered - Mailing list pgsql-sql

From Achilleas Mantzios
Subject Re: Update ordered
Date
Msg-id 52E67FF6.9060806@matrix.gatewaynet.com
Whole thread Raw
In response to Update ordered  (Andreas Joseph Krogh <andreak@officenet.no>)
List pgsql-sql
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 <andreak@officenet.no>      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




pgsql-sql by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Update ordered
Next
From: ssylla
Date:
Subject: Re: Trigger function - variable for schema name [SOLVED]