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