agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: 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:48:58 -0800
Message-ID: <52E67FEA.7060506@gmail.com> (raw)
In-Reply-To: <OfficeNetEmail.29.db58afa68192a99d.143d456e56b@prod2>
References: <OfficeNetEmail.29.db58afa68192a99d.143d456e56b@prod2>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
On 01/27/2014 07:37 AM, Andreas Joseph Krogh wrote:
> > 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;
>
> Yes, that returns ordered result, but the update CTE doens't update with
> the oldest project getting the first sequenc-nr.
> Using a DO statement, iterating over all projects ordered by "created"
> then updating each project matching the current iteration works, but I'd
> like to be able to do it in one statement as I'm sure it's possible...
Well two things;
1) Knowing what is in get_next_project_number() would be helpful?
2) Absent the above I do not see how:
update project p set project_number = get_next_project_number() from upd
where upd.id = p.id;
will actually work. No argument is being passed to
get_next_project_number() so I am not sure how it picks up what
id/created or other reference it is actually working with.
This is borne out by your success using a DO where in the iteration you
do match.
> --
> 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: <52E67FEA.7060506@gmail.com>
Permalink: ../52E67FEA.7060506@gmail.com/
Also on: postgresql.org/message-id/52E67FEA.7060506@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: <52E67FEA.7060506@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