Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7nge-0006mA-9k for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 15:01:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W7ngd-0003qk-C1 for pgsql-sql@arkaria.postgresql.org; Mon, 27 Jan 2014 15:01:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7ngc-0003qe-Ks for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 15:01:18 +0000 Received: from prod2.officenet.no ([195.159.87.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7ngW-0005RU-4r for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 15:01:18 +0000 Received: from localhost ([127.0.0.1] helo=prod2) by prod2.officenet.no with esmtp (Exim 4.76) (envelope-from ) id 1W7ngV-0008PS-RQ for pgsql-sql@postgresql.org; Mon, 27 Jan 2014 16:01:11 +0100 Date: Mon, 27 Jan 2014 16:01:11 +0100 (CET) From: Andreas Joseph Krogh To: pgsql-sql@postgresql.org Message-ID: In-Reply-To: <52E6738C.7010101@gmail.com> Subject: Re: Update ordered MIME-Version: 1.0 X-Mailer: OfficeNet Mail 1.9.0-SNAPSHOT X-Pg-Spam-Score: -2.4 (--) Content-Type: multipart/alternative; boundary="----=_Part_87_1997724356.1390834871736" 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 ------=_Part_85_1720409689.1390834871723 Content-Type: multipart/related; boundary="----=_Part_86_1205819815.1390834871723" ------=_Part_86_1205819815.1390834871723 Content-Type: multipart/alternative; boundary="----=_Part_87_1997724356.1390834871736" ------=_Part_87_1997724356.1390834871736 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 mandag 27. januar 2014 kl. 15:56:12, skrev Adrian Klaver < adrian.klaver@gmail.com >: On 01/27/2014 06= :36=20 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( >=C2=A0 =C2=A0 =C2=A0 select id from project order by created asc > ) update project p set project_number =3D get_next_project_number() from > upd where upd.id =3D 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. =C2=A0 get_next_project_number() gets the n= ext=20 project-number based on some custom logic. =C2=A0 What would be the best wa= y to=20 update all project's project-number having the oldes project get the first= =20 number returned by get_next_project_number() etc.? =C2=A0 Thanks. =C2=A0 -- Andreas Joseph Krogh =C2=A0 =C2=A0 =C2=A0 mob: +47 9= 09 56 963 Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no Public key: http://home.officenet.no/~andreak/public_key.asc =C2=A0 ------=_Part_87_1997724356.1390834871736 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 mandag 27. januar 2014 kl. 15:56:12, skrev Adrian Klaver <<= a href=3D"mailto:adrian.klaver@gmail.com" target=3D"_blank">adrian.klaver@g= mail.com>:
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"-co= lumn) and
> tried this:
> with upd as(
>=C2=A0 =C2=A0 =C2=A0 select id from project order by created asc
> ) update project p set project_number =3D get_next_project_number() fr= om
> upd where upd.id =3D 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.
=C2=A0
get_next_project_number() gets the next project-number based on some c= ustom logic.
=C2=A0
What would be the best way to update all project's project-number havi= ng the oldes project get the first number returned by get_next_project_numb= er() etc.?
=C2=A0
Thanks.
=C2=A0
--
Andreas Joseph Krogh <andreak@officenet.no>=C2=A0 =C2=A0 =C2=A0 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
=C2=A0
------=_Part_87_1997724356.1390834871736-- ------=_Part_86_1205819815.1390834871723-- ------=_Part_85_1720409689.1390834871723--