agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@gmail.com>
To: Andreas Joseph Krogh <andreak@officenet.no>
To: pgsql-sql@postgresql.org
Subject: Re: Update ordered
Date: Mon, 27 Jan 2014 07:23:56 -0800
Message-ID: <52E67A0C.5020605@gmail.com> (raw)
In-Reply-To: <OfficeNetEmail.22.db4f408b1acc02b2.143d43670c9@prod2>
References: <OfficeNetEmail.22.db4f408b1acc02b2.143d43670c9@prod2>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On 01/27/2014 07:01 AM, Andreas Joseph Krogh wrote:
> På mandag 27. januar 2014 kl. 15:56:12, skrev Adrian Klaver
> <adrian.klaver@gmail.com <mailto:adrian.klaver@gmail.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"-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.
>      > Any idea how to achive this?
>
>     That would seem to depend on what get_next_project_number() does, the
>     contents of which are unknown.
>
> get_next_project_number() gets the next project-number based on some
> custom logic.
> What would be the best way to update all project's project-number having
> the oldes project get the first number returned by
> get_next_project_number() etc.?

How are you sure it is not, have you tried something like below to test?:

with upd as(
     select id from project order by created asc
) select p.id, p.create from project_number where upd.id = p.id;

> 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


-- 
Adrian Klaver
adrian.klaver@gmail.com


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (7+ messages)  latest in thread

Message-ID: <52E67A0C.5020605@gmail.com>
Permalink:  ../52E67A0C.5020605@gmail.com/
Also on:    postgresql.org/message-id/52E67A0C.5020605@gmail.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: adrian.klaver@gmail.com, andreak@officenet.no
  Subject: Re: Update ordered
  In-Reply-To: <52E67A0C.5020605@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox