From: | Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Update ordered |
Date: | 2014-01-27 15:49:10 |
Message-ID: | 52E67FF6.9060806@matrix.gatewaynet.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)officenet(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | ssylla | 2014-01-28 06:26:43 | Re: Trigger function - variable for schema name [SOLVED] |
Previous Message | Adrian Klaver | 2014-01-27 15:48:58 | Re: Update ordered |